Fix a crash in the scene editor when saving dead custom entities. custom-entity-crash-fix
authorachurch
Sun, 03 Apr 2011 02:56:46 +0900
branchcustom-entity-crash-fix
changeset 664 0306e3085534
parent 243 f08314f4174e
child 665 966b75b0e1fa
Fix a crash in the scene editor when saving dead custom entities. This patch fixes the handling of custom entities in mods to prevent a crash when saving a custom entity which has been killed during gameplay. Thanks to FrancesF from the Bit Blot forum for providing a sample mod to reproduce the bug.
Aquaria/Game.cpp
Aquaria/Game.h
--- a/Aquaria/Game.cpp	Sat Jul 10 15:04:54 2010 +0900
+++ b/Aquaria/Game.cpp	Sun Apr 03 02:56:46 2011 +0900
@@ -2639,7 +2639,7 @@
 	if (createSaveData)
 	{
 		int idx = dsq->game->getIdxForEntityType(type);
-		entitySaveData.push_back(EntitySaveData(e, idx, usePos.x, usePos.y, rot, e->getGroupID(), e->getID()));
+		entitySaveData.push_back(EntitySaveData(e, idx, usePos.x, usePos.y, rot, e->getGroupID(), e->getID(), e->name));
 	}
 
 	addRenderObject(e, e->layer);
@@ -5549,8 +5549,8 @@
 
 			if (e->idx == -1)
 			{
-				if (!e->e->name.empty())
-					os << e->e->name << " ";
+				if (!e->name.empty())
+					os << e->name << " ";
 				else
 					os << "INVALID" << " ";
 			}
--- a/Aquaria/Game.h	Sat Jul 10 15:04:54 2010 +0900
+++ b/Aquaria/Game.h	Sun Apr 03 02:56:46 2011 +0900
@@ -604,9 +604,10 @@
 struct EntitySaveData
 {
 public:
-	EntitySaveData(Entity *e, int idx, int x, int y, int rot, int group, int id) : e(e), idx(idx), x(x), y(y), rot(rot), group(group), id(id) {}
+	EntitySaveData(Entity *e, int idx, int x, int y, int rot, int group, int id, const std::string &name) : e(e), idx(idx), x(x), y(y), rot(rot), group(group), id(id), name(name) {}
 	Entity *e;
 	int idx, x, y, rot, group, id;
+	std::string name;
 };
 
 class Game : public StateObject