Skip to content

Commit 7c5d74e

Browse files
authored
Fixing an OBJ loader bug that fragmented the loaded meshes (#4494)
The nextShapeEnd integer is a pointer in the OBJ data structures. The faceVertIndex is a vertex index counter for the mesh we are about to create. Both integers are not compatible, which causes the code to finish the meshes too early, thus writing the OBJ data incompletely into the target meshes. It wasn't noticed because for the last mesh, it process all remaining data, causing the last mesh to contain all remaining triangles. This would have been noticed if the OBJ meshes used different textures for each mesh.
1 parent 4f091f4 commit 7c5d74e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/rmodels.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,7 +4244,7 @@ static Model LoadOBJ(const char *fileName)
42444244
// walk all the faces
42454245
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
42464246
{
4247-
if (faceVertIndex >= nextShapeEnd)
4247+
if (faceId >= nextShapeEnd)
42484248
{
42494249
// try to find the last vert in the next shape
42504250
nextShape++;
@@ -4295,7 +4295,7 @@ static Model LoadOBJ(const char *fileName)
42954295
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
42964296
{
42974297
bool newMesh = false; // do we need a new mesh?
4298-
if (faceVertIndex >= nextShapeEnd)
4298+
if (faceId >= nextShapeEnd)
42994299
{
43004300
// try to find the last vert in the next shape
43014301
nextShape++;
@@ -4357,7 +4357,7 @@ static Model LoadOBJ(const char *fileName)
43574357
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
43584358
{
43594359
bool newMesh = false; // do we need a new mesh?
4360-
if (faceVertIndex >= nextShapeEnd)
4360+
if (faceId >= nextShapeEnd)
43614361
{
43624362
// try to find the last vert in the next shape
43634363
nextShape++;

0 commit comments

Comments
 (0)