iMiniB3D: remove entity parent occasional crash.

BlitzMax Forums/MiniB3D Module/iMiniB3D: remove entity parent occasional crash.

ima747(Posted 2010) [#1]
Haven't had a chance to put together a tiny demo of this yet but if it will help I can try to find the time.

When an entity changes parents in iMiniB3D sometimes it will crash in entity.mm line 95
Entity* ent=*it;
I suspect it's a problem with the lists.

This happens most in my app when 2 things are going on:
1) I'm creating and releasing a number of pivots and entity's.
2) The memory is being thrashed due to a large number of things being loaded.

Is it possible the low memory warning (not always near this) could be causing something to get released/deleted?

Also, maybe I'm missing something I don't think the looping done in this area looking for the entity is needed... elsewhere when the entity needs to get removed from it's parent's list it just uses
if(parent!=NULL){
		parent->child_list.remove(this);
	}
which should save both time and resolve the list digging crash... I will be playing around with this to see if I low anything up with that.


jhocking(Posted 2010) [#2]
I'm pretty sure I encountered this bug too, but fortunately for me I didn't really need to reparent the object so I just removed that command. Specifically, while messing around with the FreeEntity crash from the other thread I experimented with reparenting entities before freeing them.

Also, there is another place in the code where reparenting works fine, so it's clearly not all situations.

Last edited 2010


ima747(Posted 2010) [#3]
It seems that when you change an entity's parent it first removes it from the parent entity's child list. To do this it loops through the parent' entity's children looking for the targeted child, and when it find it it tell the parent to remove itself... but removing itself doesn't require being found in the list first (as it it just removed directly in other locations). And it's the looping through the list in the first place that causes the crash. I've had no problems since making the change so far.


jhocking(Posted 2010) [#4]
Now I'm paranoid that my game's moving platforms (which are done by temporarily parenting the player to the platform, and then unparenting when the player steps off) are gonna cause crashes. How is your fix implemented?

Last edited 2010


ima747(Posted 2010) [#5]
in entity.mm starting at line 91:

// remove self from parent's child list
	if(parent){
		/*list<Entity*>::iterator it;
		for(it=parent->child_list.begin();it!=parent->child_list.end();it++){
			Entity* ent=*it;
			if(ent==this) parent->child_list.remove(this);
		}*/
		parent->child_list.remove(this);
		parent=NULL;
	}

I just commented out the entity list iterator loop, and replaced it with just strait up parent->child_list.remove(this); not sure if it nulled the parent before but I did that too to ensure consistency.

As I mentioned above it was really rare and mainly happened when I was thrashing memory... not really sure why the iterator went wrong in the first place but it seems un-needed. Haven't seen any leaking (which I would expect if I was wrong about not needing the iterator) and haven't seen any crashing (which I would expect if the strait remove didn't work the way I think it does).