Warn about loading dead bodies, but handle safely.

master
Andrew Copland 2021-05-02 17:46:27 +01:00 committed by Webster Sheets
parent 9795b9deea
commit 18b4d487e2
1 changed files with 8 additions and 3 deletions

View File

@ -350,6 +350,10 @@ Body *Space::GetBodyByIndex(Uint32 idx) const
{
assert(m_bodyIndexValid);
assert(m_bodyIndex.size() > idx);
if (idx == SDL_MAX_UINT32 || m_bodyIndex.size() <= idx) {
Output("GetBodyByIndex passed bad index %u", idx);
return nullptr;
}
return m_bodyIndex[idx];
}
@ -365,8 +369,9 @@ Uint32 Space::GetIndexForBody(const Body *body) const
assert(m_bodyIndexValid);
for (Uint32 i = 0; i < m_bodyIndex.size(); i++)
if (m_bodyIndex[i] == body) return i;
assert(0);
return Uint32(-1);
assert(false);
Output("GetIndexForBody passed unknown body");
return SDL_MAX_UINT32;
}
Uint32 Space::GetIndexForSystemBody(const SystemBody *sbody) const
@ -375,7 +380,7 @@ Uint32 Space::GetIndexForSystemBody(const SystemBody *sbody) const
for (Uint32 i = 0; i < m_sbodyIndex.size(); i++)
if (m_sbodyIndex[i] == sbody) return i;
assert(0);
return Uint32(-1);
return SDL_MAX_UINT32;
}
void Space::AddSystemBodyToIndex(SystemBody *sbody)