Skip to content

Commit fc8eac2

Browse files
authored
Fix #3113: Crash on open company window with focus near the map edge (#3119)
* Fix #3113: Crash on open company window with focus near the map edge * Update CHANGELOG.md
1 parent 82b11e3 commit fc8eac2

2 files changed

Lines changed: 19 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
25.05+ (???)
22
------------------------------------------------------------------------
33
- Fix: [#2817] Deleting a vehicle that is followed on the main viewport crashes the game.
4+
- Fix: [#3113] Crash when having an on open company window with the viewport being near the map edge.
45
- Fix: [#3114] Details in the Object Selection window not drawing depending on the window position.
56

67
25.05 (2025-05-28)

src/OpenLoco/src/Ui/Window.h

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,71 +110,58 @@ namespace OpenLoco::Ui
110110

111111
struct SavedView
112112
{
113-
union
114-
{
115-
coord_t mapX;
116-
EntityId entityId;
117-
};
118-
union
119-
{
120-
coord_t mapY;
121-
uint16_t flags;
122-
};
123-
ZoomLevel zoomLevel;
124-
int8_t rotation;
125-
int16_t surfaceZ;
113+
coord_t mapX{ -1 };
114+
coord_t mapY{ -1 };
115+
EntityId entityId{ EntityId::null };
116+
uint16_t flags{};
117+
ZoomLevel zoomLevel{};
118+
int8_t rotation{};
119+
int16_t surfaceZ{};
126120

127-
SavedView() = default;
121+
constexpr SavedView() = default;
128122

129-
SavedView(coord_t mapX, coord_t mapY, ZoomLevel zoomLevel, int8_t rotation, coord_t surfaceZ)
123+
constexpr SavedView(coord_t mapX, coord_t mapY, ZoomLevel zoomLevel, int8_t rotation, coord_t surfaceZ)
130124
: mapX(mapX)
131125
, mapY(mapY)
132126
, zoomLevel(zoomLevel)
133127
, rotation(rotation)
134128
, surfaceZ(surfaceZ) {};
135129

136-
SavedView(EntityId entityId, uint16_t flags, ZoomLevel zoomLevel, int8_t rotation, coord_t surfaceZ)
130+
constexpr SavedView(EntityId entityId, uint16_t flags, ZoomLevel zoomLevel, int8_t rotation, coord_t surfaceZ)
137131
: entityId(entityId)
138132
, flags(flags)
139133
, zoomLevel(zoomLevel)
140134
, rotation(rotation)
141135
, surfaceZ(surfaceZ) {};
142136

143-
bool isEmpty() const
144-
{
145-
return mapX == -1 && mapY == -1;
146-
}
147-
148-
bool hasUnkFlag15() const
137+
constexpr bool isEmpty() const
149138
{
150-
return (flags & (1 << 14)) != 0;
139+
return mapX == -1 && mapY == -1 && entityId == EntityId::null;
151140
}
152141

153-
bool isEntityView() const
142+
constexpr bool isEntityView() const
154143
{
155144
return (flags & (1 << 15)) != 0;
156145
}
157146

158-
World::Pos3 getPos() const
147+
constexpr World::Pos3 getPos() const
159148
{
160149
if (isEntityView())
161150
{
162151
return {};
163152
}
164153

165-
return { mapX, static_cast<coord_t>(mapY & 0x3FFF), surfaceZ };
154+
return { mapX, mapY, surfaceZ };
166155
}
167156

168-
void clear()
157+
constexpr void clear()
169158
{
170159
mapX = -1;
171160
mapY = -1;
161+
entityId = EntityId::null;
172162
}
173163

174-
bool operator==(const SavedView& rhs) const
175-
{
176-
return mapX == rhs.mapX && mapY == rhs.mapY && zoomLevel == rhs.zoomLevel && rotation == rhs.rotation && surfaceZ == rhs.surfaceZ;
177-
}
164+
auto operator<=>(const SavedView& other) const = default;
178165
};
179166

180167
struct Window

0 commit comments

Comments
 (0)