Game Development Community

Crash when using scale animations

by Ivan Mandzhukov · in Collada Test · 11/07/2009 (9:46 am) · 13 replies

Engine crashes with "Vector<T>::operator[] - out of bounds array access!"

It happens only in T3D 1.0 DEBUG with billboard shapes that use scale animation.
It doesn't matter if the shape is billboard or not at all. It crashes both ways.
If the billboard uses another kind of animation (for instance move or rotate) the engine won't crash.
It happens only if the animation is scale.


My shape setup is the same as the one in this thread www.garagegames.com/community/forums/viewthread/104909
I also use the Chris Roberson's bilboard fix provided in that link.


EDIT: I have also found that any scale animation on any shape exported via COLLADA cause crash. I am not talking about scaling bones of a skined mesh but directly animating the shape with scale. These crashes happen in DEBUG. In RELEASE you cannot reproduce them always but from time to time.
At all I think COLLADA does not support scale animation. The animation can be seen in the engine , but it is unstable.

#1
11/08/2009 (2:50 pm)
I have just found the problem. I made some tests and realized that the problem is complex and very strange. In short :

if shapes exported with the old DTS exporter have bone animation in which some of the bones have key for scale and in the same time you have a shape that was exported via COLLADA and it has keys for scale too the engine crashes.

It seems that if the COLLADA shape doesn't play its scale animation but the DTS plays its own scale animation everything is OK. And opposite - if the DTS shape doesn't play it's scale animation but COLLADA plays its - it is OK again.

So I located the problem comes from scale animations for shapes exported via different exporters (DTS or COLLADA).

I don't have an idea how to fix this. Any thoughts on it? May be Chris Robertson could give a hand with that? If this can't be fixed it seems that I will have to reorganize everything exported with the DTS exporter and reexport with COLLADA. This is a lot of work and it would be better if this bug get fixed. Anyway any kind of help will be appreciated.


After a bit debugging,the problems seems to be here:
TSShapeInstance::smNodeCurrentArbitraryScales[index]

The vector size is 32,the index is 66 and we are out of bounds.
#2
11/08/2009 (8:38 pm)
Funny that you should mention this - just a couple of days ago I fixed a long-standing bug in T3D trunk (dating back to TGE I think) to do with animated node scales.

Background: There are 3 forms of scale animation. Uniform (X,Y,Z scaled by same amount), Aligned (X,Y,Z scaled by different amounts) and Arbitrary (a rotation followed by an aligned scale). Because multiple animation threads may be playing on a single shape, the TSShape animation code 'upgrades' scale animations (from Uniform->Aligned->Arbitrary) if needed. The code to do this was bugged.

I suspect the reason this has not been seen until now is that no-one was using Arbitrary scale animation, but that due to a bug in the collada loader, this type of animation was (finally) being generated.

There are 3 parts to the fix (which will also be in the next build of T3D).

1. In TSShapeLoader::generateNodeTransform in tsShapeLoader.cpp:

trans = m1.getPosition();
srot.identity();        // edit this line
scale = m1.getScale();

2. In TSShape::addSequence, add the '// Set shape flags....' code below:

if (totalFrames)
   *totalFrames = srcSeq->numKeyframes;

// Set shape flags (only the most significant scale type)
U32 curVal = mFlags & AnyScale;
mFlags &= ~(AnyScale);
mFlags |= getMax(curVal, seq.flags & AnyScale);

// Set sequence flags
seq.dirtyFlags = 0;

3. In TSShapeInstance::handleAnimatedScale in tsAnimate.cpp, change the scale conversion code:

if (animatesAlignedScale())
   code += 4;
if (animatesArbitraryScale())
   code += 8;

And the switch/case labels (note that only the labels change, I've omitted the unchanged code for clarity).

case 0:  // uniform -> uniform
case 4:  // uniform -> aligned
case 8:  // uniform -> arbitrary
   ...

case 5:  // aligned -> aligned
case 9:  // aligned -> arbitrary
   ...

case 10: // arbitrary -> arbitary
   ...

default: AssertFatal(0,"TSShapeInstance::handleAnimatedScale"); break;


switch (code)

case 0:  // uniform -> uniform
   ...

case 4:  // uniform -> aligned
case 5:  // aligned -> aligned
   ...

case 8:  // uniform -> arbitrary
case 9:  // aligned -> arbitrary
   ...

case 10: // arbitrary -> arbitary
   ...
#3
11/08/2009 (8:43 pm)
I should also point out - this has nothing to do with billboards, and (apart from the fact that it was more likely to be exposed with collada) nothing to do with collada. If you had a DTS exported shape with a mix of scale animation types you would see this bug as well.

Picasso - could you:

a) rename your thread to something like "Crash when using scale animations" so it better reflects the issue.

b) try the above fixes and let me know if it solves the problem for you? (Certainly, the file you uploaded now loads and plays without issue)
#4
11/09/2009 (5:49 am)
hi, Chris,

I tried this fix out but it didn't fix the crash issue.

I agree this has nothing to do with billboards. This is a scale animation issue.

The files I have uploaded work without applying your fix. The engine crashes when I have in the scene a Collada exported shapes with scale animation and in the same time I start playing a DTS exported shape's scale animation. If I don't start either of them so we don't have two scale animations played that were exported with the different exporters the engine won't crash.

One more thing to point : If I export the problematic DSQ (that one with scale animation) but with these field unchecked from the modify tab for the animation sequence "Uniform scale anim" and "Arbitrary scale anim" so that we don't get exported any kind of bone scale animation the engine stops crashing.

Another test I have made: bringing back my scale animation to the DTS files. If in the scene there is nothing animated via COLLADA engine doesn't crash. If I add a simple rotating sphere animated via COLLADA engine crashes.

It looks like T3D cannot handle animated art made with both DTS and COLLADA exporters if that art resided in the same scene
#5
11/09/2009 (1:24 pm)
I just wanted to tell that I started remaking all my art assets with the DTS exporter. Collada with animation is just impossible. I give up. I made it working but it leads to misterious crashes. I want to point out that I started having crashing issues as soon as I started working with collada animated shapes. Anyway it is great that there is COLLADA because combined with PureLight users can achieve tremendous and incredible environments but I just quit working with COLLADA animations for the time being.

Anyway I looked in the T3D official examples (StarterFPS, etc.). I couldn't find anywhere any kind of asset that use COLLADA animation. Gideon(the player) , health kits , everything is made there using the old good DTS exporter. Nothing personally , but may be GG team has encountered problems with collada animated shapes and that's why nothing was made with it in the examples.

If I encounter problems even with the remade assets via the DTS exporter I will let you know.

By the way it will be good if not integrating the fix above in the official next T3D release. It will potentially lead to problems. I would suggest not only you , Chris , but all the GG team to spend more time testing everything before releasing because my experience tells that I have lost not days , but weeks debugging things that are supposed to work.
#6
11/09/2009 (1:41 pm)
Quote:I tried this fix out but it didn't fix the crash issue.

Bugger.

Quote:The files I have uploaded work without applying your fix.

I thought you said they crashed T3D? Anyway, can you provide the pair of DTS and DAE files to reproduce the crash?
#7
11/09/2009 (1:52 pm)
In fact I spend this morning making a DTS file that would reproduce the bug because I don't want to share my player DTS character. I couldn't reproduce it with another shape.

I told you the COLLADA file (the uploaded one) crashes T3D. Yes it crashes it when I have a scale animation in the Dts file. When I removed it with another that doesn't use scale the two shapes in pair in the scene didn't crash T3D.

As far as I replaced and reexported the problematic COLLADA asset with a DTS asset that uses the same animation T3D stopped crashing.
#8
11/09/2009 (1:57 pm)
I cannot share my player DTS for testing. I hope you understand that.
I can't tell where the problem is but removing the animated COLLADA files from my project stopped crashing T3D. I have also reexported some of them into DTS. T3D is still stable with only DTS shapes and my level(COLLADA shape). I can't tell till now, but currently it is stable. Anyway if a crash appears ,even if there are only DTS animated shapes in the scene I will let you know.

Actually i lost a whole day to prepare a shape that crashes T3D for you,Chris, and you call me a bugger ?
This is an incredible bug and it is very difficult to reproduce it.
I think tomorrow i'll be able to send you the files.
#9
11/09/2009 (5:10 pm)
Quote:I cannot share my player DTS for testing. I hope you understand that.

Sure. I was hoping you had another one available. The only modeling program I have handy (Milkshape) does not export scale animations.

Quote:Actually i lost a whole day to prepare a shape that crashes T3D for you,Chris, and you call me a bugger ?

A misunderstanding. In NZ, bugger is often used in place of damn/blast etc to express dissatisfaction with something. In this case, the fact that the fix did not solve the problem for you. Sorry for any unintentional offence caused.
#10
11/10/2009 (1:46 pm)
Chris,
i can not reproduse the bug with another shape.It just works.
I can not understand why the previous player dae crashed T3D,also i can not find the difference between the files.

I only found this crash is related with the arbitrary scale animation.
I re-worked all the scale animations with the dts exporter,and now T3D is stable.Collada has problems with only scale animations.
If scale animations are not used,the rest Collada animation works well with no issues.

I cleaned the whole scene and left the player only.
The scale animation start index is 66 in my case.Still no crashes.
I insert a collada shape with a scale animation.
Its scale index is 13. The array size is 80.
66>13 and we are out of bounds.
I can not understand why T3D use 66 for the next shape,there is a conflict with the scale membership of the sequences.
This issue is missing when i use the dts exporter,so i think the collada loader skips to register something on the shape instance.
I am not familiar with the loader.

So now i will use the dts exporter for scale animations.
Therefore i have a working solution for me.
#11
11/10/2009 (8:24 pm)
Hi Picasso,

If you've still interested, I think I might have found the problem. In addition to the code changes above, could you try changing the end of the TSShapeLoader::generateSequences() method in tsShapeLoader.cpp to look like this:

if (seq.iflMatters.testAll())
         seq.dirtyFlags |= TSShapeInstance::IflDirty;

      // Set shape flags (only the most significant scale type)
      U32 curVal = shape->mFlags & TSShape::AnyScale;
      shape->mFlags &= ~(TSShape::AnyScale);
      shape->mFlags |= getMax(curVal, seq.flags & TSShape::AnyScale);
   }
}

Without this, Torque would not resize the TSShapeInstance::smNodeCurrentArbitraryScales vector for the collada shape, leading to the crash.
#12
11/11/2009 (4:06 am)
Chris,you're the man!
Collada animations now play without issues.
#13
08/27/2010 (6:17 pm)
Chris, the problem arbitrary scale animations (somehow ?!?) still persist on dts objects.Dae ones are fine.
I use an arbitrary scale on objects without a bone system,I mean that I have not used the skin modifier in order to do some optimizations.
Actually those shapes are still problematic.


I resize the problematic vector :
smNodeCurrentArbitraryScales.setSize(mShape->nodes.size());

just before:

In tsThread.cpp
for (i=0; i<mShape->nodes.size(); i++)
		 {  
            if (mTransitionScaleNodes.test(i))
            {
               mNodeReferenceScaleFactors[i] = smNodeCurrentArbitraryScales[i].mScale;
               mNodeReferenceArbitraryScaleRots[i].set(smNodeCurrentArbitraryScales[i].mRotate);
            }
         }

and now the dts arbitrary scale works fine.
I can not understand why handleDefaultScale() in tsAnimate.cpp cannot resize the vector correctly.This is why I resize it manually.
I'll be glad if you take a look at this vector,because this was a long standing bug - just to verify if this is a correct solution.
Thanks again!