Update of /cvsroot/super-tux/supertux/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4541
Modified Files:
sector.cpp sector.h
Log Message:
- don't add new objects until end of Sector::action()
- fixes cases where adding a new object while iterating over the objects can cause a crash
Index: sector.h
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/sector.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sector.h 2 Jun 2004 23:33:35 -0000 1.3
+++ sector.h 8 Jun 2004 19:48:33 -0000 1.4
@@ -148,6 +148,7 @@
InteractiveObjects interactive_objects;
typedef std::vector<GameObject*> GameObjects;
GameObjects gameobjects;
+ GameObjects gameobjects_new; // For newly created objects
private:
typedef std::vector<SpawnPoint*> SpawnPoints;
Index: sector.cpp
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- sector.cpp 8 Jun 2004 17:44:29 -0000 1.5
+++ sector.cpp 8 Jun 2004 19:48:33 -0000 1.6
@@ -274,7 +274,8 @@
void
Sector::add_object(GameObject* object)
{
- // XXX a bit hackish, at least try to keep the number of these things down...
+ gameobjects_new.push_back(object);
+#if 0
BadGuy* badguy = dynamic_cast<BadGuy*> (object);
if(badguy)
badguys.push_back(badguy);
@@ -296,6 +297,8 @@
interactive_objects.push_back(interactive_object);
gameobjects.push_back(object);
+
+#endif
}
void
@@ -397,6 +400,35 @@
++i;
}
}
+
+ /* add newly created objects */
+ for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
+ i != gameobjects_new.end(); ++i)
+ {
+ BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
+ if(badguy)
+ badguys.push_back(badguy);
+ Bullet* bullet = dynamic_cast<Bullet*> (*i);
+ if(bullet)
+ bullets.push_back(bullet);
+ Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
+ if(upgrade)
+ upgrades.push_back(upgrade);
+ Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
+ if(trampoline)
+ trampolines.push_back(trampoline);
+ FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
+ if(flying_platform)
+ flying_platforms.push_back(flying_platform);
+ InteractiveObject* interactive_object
+ = dynamic_cast<InteractiveObject*> (*i);
+ if(interactive_object)
+ interactive_objects.push_back(interactive_object);
+
+ gameobjects.push_back(*i);
+ }
+ gameobjects_new.clear();
+
}
void
|