Skip to content

Commit bfafcf4

Browse files
committed
Fixed crash on incompatible save click (closes #226)
You will see ui_st_error instead of a level name. You still shouldn't try to load this save.
1 parent 99fefca commit bfafcf4

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/xrAICore/Navigation/game_graph_inline.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ IC const GameGraph::_GRAPH_ID& GameGraph::CHeader::vertex_count() const { return
107107
IC const u32& GameGraph::CHeader::edge_count() const { return (m_edge_count); }
108108
IC const u32& GameGraph::CHeader::death_point_count() const { return (m_death_point_count); }
109109
IC const GameGraph::LEVEL_MAP& GameGraph::CHeader::levels() const { return (m_levels); }
110+
111+
IC bool GameGraph::CHeader::level_exist(const _LEVEL_ID& id) const
112+
{
113+
return levels().find(id) != levels().end();
114+
}
115+
116+
IC bool GameGraph::CHeader::level_exist(pcstr level_name) const
117+
{
118+
for (const auto& level : levels())
119+
if (xr_strcmp(level.second.name(), level_name) == 0)
120+
return true;
121+
return false;
122+
}
123+
110124
IC const GameGraph::SLevel& GameGraph::CHeader::level(const _LEVEL_ID& id) const
111125
{
112126
LEVEL_MAP::const_iterator I = levels().find(id);

src/xrAICore/Navigation/game_graph_space.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class CHeader
117117
IC const u32& death_point_count() const;
118118
IC const xrGUID& guid() const;
119119
IC const LEVEL_MAP& levels() const;
120+
IC bool level_exist(const _LEVEL_ID& id) const;
121+
IC bool level_exist(pcstr level_name) const;
120122
IC const SLevel& level(const _LEVEL_ID& id) const;
121123
IC const SLevel& level(LPCSTR level_name) const;
122124
IC const SLevel* level(LPCSTR level_name, bool) const;

src/xrGame/saved_game_wrapper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ CSavedGameWrapper::CSavedGameWrapper(LPCSTR saved_game_name)
161161
{
162162
CGameGraph graph(*chunk);
163163
m_level_id = graph.vertex(object->m_tGraphID)->level_id();
164-
m_level_name = graph.header().level(m_level_id).name();
164+
if (graph.header().level_exist(m_level_id))
165+
m_level_name = graph.header().level(m_level_id).name();
166+
else
167+
m_level_name = CStringTable().translate("ui_st_error");
165168
}
166169

167170
chunk->close();

0 commit comments

Comments
 (0)