resolved a few segfaults with animation system (#4635)
* Update rmodels.c resolves segfault with missing bone weights or bone IDs * Update rmodels.c segfault with animation and missing normals/animnormals * correct place.
This commit is contained in:
parent
7868d600f4
commit
a7686c47b3
1 changed files with 6 additions and 2 deletions
|
@ -2286,6 +2286,7 @@ void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update all bones and boneMatrices of first mesh with bones.
|
// Update all bones and boneMatrices of first mesh with bones.
|
||||||
for (int boneId = 0; boneId < anim.boneCount; boneId++)
|
for (int boneId = 0; boneId < anim.boneCount; boneId++)
|
||||||
{
|
{
|
||||||
|
@ -2350,6 +2351,8 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
bool updated = false; // Flag to check when anim vertex information is updated
|
bool updated = false; // Flag to check when anim vertex information is updated
|
||||||
const int vValues = mesh.vertexCount*3;
|
const int vValues = mesh.vertexCount*3;
|
||||||
|
|
||||||
|
if ((mesh.boneWeights==NULL) || (mesh.boneIds==NULL)) continue; // skip if missing bone data, causes segfault without on some models
|
||||||
|
|
||||||
for (int vCounter = 0; vCounter < vValues; vCounter += 3)
|
for (int vCounter = 0; vCounter < vValues; vCounter += 3)
|
||||||
{
|
{
|
||||||
mesh.animVertices[vCounter] = 0;
|
mesh.animVertices[vCounter] = 0;
|
||||||
|
@ -2378,7 +2381,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
|
|
||||||
// Normals processing
|
// Normals processing
|
||||||
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
||||||
if (mesh.normals != NULL)
|
if ((mesh.normals != NULL) && (mesh.animNormals != NULL ))
|
||||||
{
|
{
|
||||||
animNormal = (Vector3){ mesh.normals[vCounter], mesh.normals[vCounter + 1], mesh.normals[vCounter + 2] };
|
animNormal = (Vector3){ mesh.normals[vCounter], mesh.normals[vCounter + 1], mesh.normals[vCounter + 2] };
|
||||||
animNormal = Vector3Transform(animNormal,model.meshes[m].boneMatrices[boneId]);
|
animNormal = Vector3Transform(animNormal,model.meshes[m].boneMatrices[boneId]);
|
||||||
|
@ -2392,7 +2395,8 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
if (updated)
|
if (updated)
|
||||||
{
|
{
|
||||||
rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position
|
rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position
|
||||||
rlUpdateVertexBuffer(mesh.vboId[2], mesh.animNormals, mesh.vertexCount*3*sizeof(float), 0); // Update vertex normals
|
if (mesh.normals != NULL)
|
||||||
|
rlUpdateVertexBuffer(mesh.vboId[2], mesh.animNormals, mesh.vertexCount*3*sizeof(float), 0); // Update vertex normals
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue