encima / encima/jsc3d

Infinite loop if loading OBJ with unclean face definitions

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
auto-migrated Priority-Medium Type-Defect
Dominant language
HTML
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

```
What steps will reproduce the problem?
I exported a 3D model from Blender to OBJ format. But the OBJ file seems to
contain some faces with only 2 vertices (Reason unknown). This crashes the
jsc3d viewer. There is no problem opening the file with Blender.

What is the expected output? What do you see instead?
I expected the "illegal" faces would be ignored. Instead, the jsc3d library
runs into infinite loop.

What version of the product are you using? On what operating system?
jsc3d 0.7.2,
WinXP, Win7

Please provide any additional information below.
I debugged the library and found the reason for the infinite loop in several
do-while-statements, which test for the sequence end "-1" in the index buffer
(ibuf[j++] != -1). But if a sequence at the end of the buffer contains only 2
elements, this test clause can never become true.

Anyway, I suggest a very easy fix: Just ignore faces with less than 3 elements
when parsing the file.
Here's the code:

=== Code for "JSC3D.ObjLoader.prototype.parseObj" ===

case 'f':
if(tokens.length >= 4) { // Add this condition
for(var j=1; j 1 && refs[1] != '') {
if(!curMesh.texCoordIndexBuffer)
curMesh.texCoordIndexBuffer = [];
curMesh.texCoordIndexBuffer.push( parseInt(refs[1]) - 1 );
}
}

curMesh.indexBuffer.push(-1);
if(curMesh.texCoordIndexBuffer)
curMesh.texCoordIndexBuffer.push(-1);
}
break;

=== End of code ===

```

Original issue reported on code.google.com by `atan...@gmail.com` on 29 Apr 2012 at 3:16

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.