Skip to content

Commit

Permalink
Fixed crash on incompatible save click (closes OpenXRay#226)
Browse files Browse the repository at this point in the history
You will see ui_st_error instead of a level name. You still shouldn't
try to load this save.
  • Loading branch information
Xottab-DUTY committed Aug 10, 2018
1 parent 99fefca commit bfafcf4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/xrAICore/Navigation/game_graph_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ IC const GameGraph::_GRAPH_ID& GameGraph::CHeader::vertex_count() const { return
IC const u32& GameGraph::CHeader::edge_count() const { return (m_edge_count); }
IC const u32& GameGraph::CHeader::death_point_count() const { return (m_death_point_count); }
IC const GameGraph::LEVEL_MAP& GameGraph::CHeader::levels() const { return (m_levels); }

IC bool GameGraph::CHeader::level_exist(const _LEVEL_ID& id) const
{
return levels().find(id) != levels().end();
}

IC bool GameGraph::CHeader::level_exist(pcstr level_name) const
{
for (const auto& level : levels())
if (xr_strcmp(level.second.name(), level_name) == 0)
return true;
return false;
}

IC const GameGraph::SLevel& GameGraph::CHeader::level(const _LEVEL_ID& id) const
{
LEVEL_MAP::const_iterator I = levels().find(id);
Expand Down
2 changes: 2 additions & 0 deletions src/xrAICore/Navigation/game_graph_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class CHeader
IC const u32& death_point_count() const;
IC const xrGUID& guid() const;
IC const LEVEL_MAP& levels() const;
IC bool level_exist(const _LEVEL_ID& id) const;
IC bool level_exist(pcstr level_name) const;
IC const SLevel& level(const _LEVEL_ID& id) const;
IC const SLevel& level(LPCSTR level_name) const;
IC const SLevel* level(LPCSTR level_name, bool) const;
Expand Down
5 changes: 4 additions & 1 deletion src/xrGame/saved_game_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ CSavedGameWrapper::CSavedGameWrapper(LPCSTR saved_game_name)
{
CGameGraph graph(*chunk);
m_level_id = graph.vertex(object->m_tGraphID)->level_id();
m_level_name = graph.header().level(m_level_id).name();
if (graph.header().level_exist(m_level_id))
m_level_name = graph.header().level(m_level_id).name();
else
m_level_name = CStringTable().translate("ui_st_error");
}

chunk->close();
Expand Down

0 comments on commit bfafcf4

Please sign in to comment.