T3D 1.1 Final - Using setTransform() to move the listener into an SFXSpace can corrupt SFXWorld:: mScopeStack
by Michael Reino · in Torque 3D Professional · 02/26/2012 (11:39 pm) · 1 replies
Build: 1.1 Final Pro and 1.2 bug-fix
Platform: Windows XP 32
Target: Visual Studio 2010. Easy to see in the debugger, but takes a long time to crash a release build.
Issue: Using setTransform() to 'teleport' into an SFXSpace causes more objects to be pushed onto mScopeStack than get removed when leaving the SFXSpace.
Steps to repeat: This is complicated to reproduce, but can be setup in the EmptyRoom.
1. Add two unique SFX spaces to a mission. It's important that the zones do not overlap in the x or y dimensions. I used positions "0 0 0" and "50 50 0" with both having a scale of "20 20 20"
2. In Engine/source/sfx/sfxWorld.h place 2 breakpoints. One in _onScopeIn() (line 350: mScopeStack.insert( iter, Scope( sortValue, object ) );) and one in _onScopeOut() (line 374: mScopeStack.erase( index );)
3. Launch the game in the debugger and open the mission.
4. Open the console and alternately enter LocalClientConnection.player.setTransform("50 50 0"); and LocalClientConnection.player.setTransform("0 0 0");
5. Watch the breakpoints hit and note the value of mElementCount in mScopeStack. There are 2 calls to _onScopeIn() (would be 3 if the SFXSpaces were not on the same z plane) for every call to _onScopeOut() so the stack keeps growing and never gets cleaned up.
We use teleports and SFXSpaces in our game so this is a real problem for us. After enough teleporting around the level, the stack is hopelessly corrupt and does crash the release build.
Suggested Fix: I'm not sure if this is a fix or a work-around, but it does prevent the bug from occurring. I added:
Platform: Windows XP 32
Target: Visual Studio 2010. Easy to see in the debugger, but takes a long time to crash a release build.
Issue: Using setTransform() to 'teleport' into an SFXSpace causes more objects to be pushed onto mScopeStack than get removed when leaving the SFXSpace.
Steps to repeat: This is complicated to reproduce, but can be setup in the EmptyRoom.
1. Add two unique SFX spaces to a mission. It's important that the zones do not overlap in the x or y dimensions. I used positions "0 0 0" and "50 50 0" with both having a scale of "20 20 20"
2. In Engine/source/sfx/sfxWorld.h place 2 breakpoints. One in _onScopeIn() (line 350: mScopeStack.insert( iter, Scope( sortValue, object ) );) and one in _onScopeOut() (line 374: mScopeStack.erase( index );)
3. Launch the game in the debugger and open the mission.
4. Open the console and alternately enter LocalClientConnection.player.setTransform("50 50 0"); and LocalClientConnection.player.setTransform("0 0 0");
5. Watch the breakpoints hit and note the value of mElementCount in mScopeStack. There are 2 calls to _onScopeIn() (would be 3 if the SFXSpaces were not on the same z plane) for every call to _onScopeOut() so the stack keeps growing and never gets cleaned up.
We use teleports and SFXSpaces in our game so this is a real problem for us. After enough teleporting around the level, the stack is hopelessly corrupt and does crash the release build.
Suggested Fix: I'm not sure if this is a fix or a work-around, but it does prevent the bug from occurring. I added:
// If the object is already on the scope stack, do not add it again
S32 index = _findScope( object );
if( index != -1 )
return;above:// Find where to insert the object into the stack. typename Vector< Scope >::iterator iter = mScopeStack.begin();in SFXWorld::_onScopeIn()
Richard Marrevee
R.G.S - Richards Game Studio