changeset 476:78a1eb57c074

Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 22 Apr 2010 01:18:44 +0000
parents afde89c1d50b
children 6b33d80b468b
files demos/shooter/scripts/common/baseobject.py demos/shooter/scripts/scene.py
diffstat 2 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/demos/shooter/scripts/common/baseobject.py	Wed Apr 21 18:20:13 2010 +0000
+++ b/demos/shooter/scripts/common/baseobject.py	Thu Apr 22 01:18:44 2010 +0000
@@ -112,10 +112,10 @@
 		self._velocity.y += (norm.y * (self._scene.timedelta/1000.0))/self._yscale
 		
 	def removeFromScene(self):
-		self._scene.removeObjectFromScene(self)
-		if self._instance:
-			self._layer.deleteInstance(self._instance)
-			self._instance = None
+		self._scene.queueObjectForRemoval(self)
+#		if self._instance:
+#			self._layer.deleteInstance(self._instance)
+#			self._instance = None
 
 	def _isRunning(self):
 		return self._running
--- a/demos/shooter/scripts/scene.py	Wed Apr 21 18:20:13 2010 +0000
+++ b/demos/shooter/scripts/scene.py	Thu Apr 22 01:18:44 2010 +0000
@@ -52,6 +52,7 @@
 		
 		self._player = None
 		self._projectiles = list()
+		self._objectstodelete = list()
 		
 		self._maxnodes = 128
 		self._xscale = 0
@@ -172,6 +173,9 @@
 	def endLevel(self):
 		self._world.endLevel()
 		
+	def queueObjectForRemoval(self, obj):
+		self._objectstodelete.append(obj)
+		
 	def removeAllProjectiles(self):
 		projtodelete = list()
 		for p in self._projectiles:
@@ -219,6 +223,8 @@
 		for node in self._nodes:
 			if obj in node.spaceobjects:
 				node.spaceobjects.remove(obj)
+				self._layer.deleteInstance(obj.instance)
+				obj.instance = None
 				return
 	
 	def attachCamera(self, cam):
@@ -318,6 +324,13 @@
 			if p in self._projectiles:
 				p.destroy()
 				self._projectiles.remove(p)
+		
+		for obj in self._objectstodelete:
+			self.removeObjectFromScene(obj)
+			self._layer.deleteInstance(obj.instance)
+			obj.instance = None
+			
+		self._objectstodelete = list()
 
 				
 	def _getPlayer(self):