Skip to content

Commit

Permalink
UPBGE: Fix object with timer deleted before timer end.
Browse files Browse the repository at this point in the history
Previously the object in m_tempObjectList were removed only
when the timer ended, but if the user ask to delete the object
before the timer does, then the object still remains in
m_tempObjectList and at the next logic frame we will intent
to read the timer property from all the object in the list
and we will get invalid pointers.

To solve this issue the object is removed from the temporary
list only in NewRemoveObject.

Fix issue: #565.
  • Loading branch information
panzergame committed Aug 19, 2017
1 parent a96204a commit 47aa533
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions source/gameengine/Ketsji/KX_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@ bool KX_Scene::NewRemoveObject(KX_GameObject *gameobj)
m_euthanasyobjects.erase(euthit);
}

const std::vector<KX_GameObject *>::const_iterator tempit = std::find(m_tempObjectList.begin(), m_tempObjectList.end(), gameobj);
if (tempit != m_tempObjectList.end()) {
m_tempObjectList.erase(tempit);
}

if (gameobj == m_active_camera)
{
//no AddRef done on m_active_camera so no Release
Expand Down Expand Up @@ -1456,29 +1461,22 @@ void KX_Scene::RenderDebugProperties(RAS_DebugDraw& debugDraw, int xindent, int
void KX_Scene::LogicBeginFrame(double curtime, double framestep)
{
// have a look at temp objects ...
for (std::vector<KX_GameObject *>::iterator it = m_tempObjectList.begin(); it != m_tempObjectList.end();) {
KX_GameObject *gameobj = *it;
for (KX_GameObject *gameobj : m_tempObjectList) {
CFloatValue* propval = (CFloatValue *)gameobj->GetProperty("::timebomb");

if (propval)
{
float timeleft = propval->GetNumber() - framestep;
if (propval) {
const float timeleft = propval->GetNumber() - framestep;

if (timeleft > 0)
{
if (timeleft > 0) {
propval->SetFloat(timeleft);
++it;
}
else
{
// remove obj
else {
// Remove obj, remove the object from tempObjectList in NewRemoveObject only.
DelayedRemoveObject(gameobj);
it = m_tempObjectList.erase(it);
}
}
else
{
// all object is the tempObjectList should have a clock
else {
// All object is the tempObjectList should have a clock.
BLI_assert(false);
}
}
Expand Down

0 comments on commit 47aa533

Please sign in to comment.