From: Ryan Flegel Date: Tue, 8 Jun 2004 19:48:33 +0000 (+0000) Subject: - don't add new objects until end of Sector::action() X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c90c871ea557d6d53d546382932fe7f820dd4ee8;p=supertux.git - 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 SVN-Revision: 1436 --- diff --git a/src/sector.cpp b/src/sector.cpp index b9b959abd..bef23cfae 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -274,7 +274,8 @@ Sector::write(LispWriter& writer) 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 (object); if(badguy) badguys.push_back(badguy); @@ -296,6 +297,8 @@ Sector::add_object(GameObject* object) interactive_objects.push_back(interactive_object); gameobjects.push_back(object); + +#endif } void @@ -397,6 +400,35 @@ Sector::action(float elapsed_time) ++i; } } + + /* add newly created objects */ + for(std::vector::iterator i = gameobjects_new.begin(); + i != gameobjects_new.end(); ++i) + { + BadGuy* badguy = dynamic_cast (*i); + if(badguy) + badguys.push_back(badguy); + Bullet* bullet = dynamic_cast (*i); + if(bullet) + bullets.push_back(bullet); + Upgrade* upgrade = dynamic_cast (*i); + if(upgrade) + upgrades.push_back(upgrade); + Trampoline* trampoline = dynamic_cast (*i); + if(trampoline) + trampolines.push_back(trampoline); + FlyingPlatform* flying_platform = dynamic_cast (*i); + if(flying_platform) + flying_platforms.push_back(flying_platform); + InteractiveObject* interactive_object + = dynamic_cast (*i); + if(interactive_object) + interactive_objects.push_back(interactive_object); + + gameobjects.push_back(*i); + } + gameobjects_new.clear(); + } void diff --git a/src/sector.h b/src/sector.h index fea92d3e3..96a2e45c9 100644 --- a/src/sector.h +++ b/src/sector.h @@ -148,6 +148,7 @@ public: // ugly InteractiveObjects interactive_objects; typedef std::vector GameObjects; GameObjects gameobjects; + GameObjects gameobjects_new; // For newly created objects private: typedef std::vector SpawnPoints;