vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
470 stars 75 forks source link

NodeBuilder infinite recursion when setting WorldMatrix, then calling UseTrans/Rot/Scale #37

Closed ptasev closed 4 years ago

ptasev commented 4 years ago

On the latest master there is an infinite recursion if you do the following resulting in a StackOverflowException.

var nb = nodeBuilder.CreateNode();
nb.WorldMatrix = worldMatrix; // Comment out this line to fix bug
var ttb = nb.UseTranslation().UseTrackBuilder(TrackName);
var rtb = nb.UseRotation().UseTrackBuilder(TrackName);
var stb = nb.UseScale().UseTrackBuilder(TrackName);
vpenades commented 4 years ago

Hmm... I couldn't reproduce that example as is.... it just works fine.

Could it be possible to see a larger example?

ptasev commented 4 years ago

Hmm, I just did this in a new project and was able to get the error. I just learned that it only happens if the matrix is not identity.

var nbr = new NodeBuilder("Dummy1");
var nb = nbr.CreateNode("Dummy2");
nb.WorldMatrix = new Matrix4x4(1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,1);
var ttb = nb.UseTranslation().UseTrackBuilder("Default");
var rtb = nb.UseRotation().UseTrackBuilder("Default");
var stb = nb.UseScale().UseTrackBuilder("Default");
vpenades commented 4 years ago

Indeed, it was doing an infinite recursive loop, I've just fixed it.

Thanks!