Skip to content

Commit 5466e72

Browse files
committed
ecere/gfx/3D/E3D: Added safety null checks on mesh skin
1 parent 47b0517 commit 5466e72

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

ecere/src/gfx/3D/models/e3d/e3dRead.ec

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -896,30 +896,35 @@ static void readBlocks(E3DContext ctx, File f, DisplaySystem displaySystem, E3DB
896896
case skinBindMatrix:
897897
{
898898
MeshSkin skin = mesh.skin;
899-
900-
readMatrix(f, skin.bindShapeMatrix);
901-
skin.bsIsIdentity = skin.bindShapeMatrix.isIdentity();
902-
if(skin.bsIsIdentity)
903-
skin.invShape.Identity();
904-
else
905-
skin.invShape.Inverse(skin.bindShapeMatrix);
899+
if(skin)
900+
{
901+
readMatrix(f, skin.bindShapeMatrix);
902+
skin.bsIsIdentity = skin.bindShapeMatrix.isIdentity();
903+
if(skin.bsIsIdentity)
904+
skin.invShape.Identity();
905+
else
906+
skin.invShape.Inverse(skin.bindShapeMatrix);
907+
}
906908
break;
907909
}
908910
case skinBones:
909911
{
910-
byte count;
911-
int i;
912912
MeshSkin skin = mesh.skin;
913-
Array<SkinBone> bones = skin.bones;
913+
if(skin)
914+
{
915+
byte count;
916+
int i;
917+
Array<SkinBone> bones = skin.bones;
914918

915-
f.Read(&count, sizeof(byte), 1);
916-
bones.size = count;
919+
f.Read(&count, sizeof(byte), 1);
920+
bones.size = count;
917921

918-
for(i = 0; i < count; i++)
919-
{
920-
bones[i].name = readString(f);
921-
readMatrix(f, bones[i].invBindMatrix);
922-
bones[i].bsInvBindMatrix.Multiply(skin.bindShapeMatrix, bones[i].invBindMatrix);
922+
for(i = 0; i < count; i++)
923+
{
924+
bones[i].name = readString(f);
925+
readMatrix(f, bones[i].invBindMatrix);
926+
bones[i].bsInvBindMatrix.Multiply(skin.bindShapeMatrix, bones[i].invBindMatrix);
927+
}
923928
}
924929
break;
925930
}

0 commit comments

Comments
 (0)