Loading textured meshes (obj+mtl) leads to crash in osg 3.4.1

90 views
Skip to first unread message

Tom Pollok

unread,
Jan 10, 2020, 1:01:57 PM1/10/20
to OpenSceneGraph Users
When loading a textured mesh from an obj file with mtl + texture file, openscenegraph crashes.

I use openscenegraph 3.4.1. Does anybody know if that issue has been fixed in newer versions?

Robert Osfield

unread,
Jan 10, 2020, 1:45:26 PM1/10/20
to OpenSceneGraph Users
On Friday, 10 January 2020 18:01:57 UTC, Tom Pollok wrote:
When loading a textured mesh from an obj file with mtl + texture file, openscenegraph crashes.

I use openscenegraph 3.4.1. Does anybody know if that issue has been fixed in newer versions?

I don;t recall reports of crashes associated with .obj.

Could you provide a link to the model that is causing the problem?

Could you provide a stack trace?

What platform are you working on?  Did you build the OSG yourself?  

What hardware are you working on?

Cheers,
Robert,

Tom Pollok

unread,
Jan 13, 2020, 6:12:48 AM1/13/20
to OpenSceneGraph Users
I added a zip file with the mesh. It happens when loading that obj file.


Pw: osg

I have to check for the stack trace again.

osgDB::Options* opt = new osgDB::Options;
opt->setOptionString("noRotation");

osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(pathToObjFile, opt);

Im using two windows machines with intel processors (64bit).
OSG was built by ourselves.
One has an integrated intel graphics unit and one with a Nvidia 2080Ti.

Tom Pollok

unread,
Jan 13, 2020, 9:07:49 AM1/13/20
to OpenSceneGraph Users
Hello Robert,

I added a minimal reproducer and a stracktrace (release). Unfortunately i only have release builds on this machine, but I could provide debug stack trace from another system later...

Best,
Tom
osgTest.zip
stacktrace_release.txt

L. Voerman

unread,
Jan 14, 2020, 8:10:27 AM1/14/20
to OpenSceneGraph Users
repost in google group; It seems like my reply to the mailing list does not show up in google groups.

Hi Tom,
I think your obj file is invalid, as the faces all reference normal "0" and 
1> no normals are provided
2> normal indices start at 1 (according to wikipedia)

if I reduce your obj file to just the first face (removing material and all but vertex/texcoord 0-1-2) ( attached )
I get the same crash with
osgconv DataFace1.obj
removing the /0 (normal ref) three times fixes the problem - same works for the large file (with textures working)
Laurens.

Robert Osfield

unread,
Jan 14, 2020, 8:36:29 AM1/14/20
to OpenSceneGraph Users
I have looked at the model with the 3.6 branch and get the crash and concur with Luarens - the model is broken, it has normal indices assigned to the faces but no normal array.  The crash occurs because the OSG's obj plugin is assuming that if normal indices are provided they are valid normal indices.

Where did this model come from?

Tom Pollok

unread,
Jan 14, 2020, 8:54:37 AM1/14/20
to OpenSceneGraph Users
I used OpenMVS to create it:


I can also view the model using MeshLab or other tools.

Is it possible to fix the invalid references in openscenegraph?

Tom Pollok

unread,
Jan 14, 2020, 9:13:00 AM1/14/20
to OpenSceneGraph Users
Hello Laurens,

thank you for your investigation!

Best,
Tom

Robert Osfield

unread,
Jan 14, 2020, 9:23:15 AM1/14/20
to OpenSceneGraph Users

On Tuesday, 14 January 2020 13:54:37 UTC, Tom Pollok wrote:
I used OpenMVS to create it:


The model isn't a valid .obj file, I am not familiar with OpenMVS and as I have my own open source projects to manage I'll leave it to others to fix OpenMVS.  I would suggest having a look at the .obj export yourself or creating an Issue for it, but a quick look at the github page makes me wonder if the Issue tracker is being largely ignored or misused at there are 95 items in there.
 
I can also view the model using MeshLab or other tools.

These other tools must have added a catch for this type of invalid model.
 

Is it possible to fix the invalid references in openscenegraph?

I am currently modifying the OSG's obj loader to catch the invalid data as crashing is as much as a bug as the dodgy data.  I expect to get a fix checked in this afternoon so it'll be part of the OSG-3.6 branch and the up coming 3.6.5 release.

Robert.
 

Tom Pollok

unread,
Jan 14, 2020, 9:32:13 AM1/14/20
to OpenSceneGraph Users
Thank you Robert for your help and thank you for all your efforts for openscenegraph!
Best, Tom.

Robert Osfield

unread,
Jan 14, 2020, 10:01:11 AM1/14/20
to OpenSceneGraph Users
I have checked in a workaround for the invalid indices to the 3.6 branch and master:

Tom Pollok

unread,
Jan 14, 2020, 10:25:52 AM1/14/20
to OpenSceneGraph Users
Thank you for the workaround.

So as far as i understand you only add the texture coordinate and normal, if there exists one with a index greater than 0 and less then the number of normals or texture coordinates.
So that means that openscenegraph now will be able to display the textured mesh, even if the normals are missing, right?

Robert Osfield

unread,
Jan 14, 2020, 11:25:27 AM1/14/20
to OpenSceneGraph Users, OpenSceneGraph Users
On Tue, 14 Jan 2020 at 15:26, 'Tom Pollok' via OpenSceneGraph Users <osg-...@googlegroups.com> wrote:
Thank you for the workaround.

So as far as i understand you only add the texture coordinate and normal, if there exists one with a index greater than 0 and less then the number of normals or texture coordinates.
So that means that openscenegraph now will be able to display the textured mesh, even if the normals are missing, right?

Yes, that's correct, you'll get a textured mesh with no normals assigned.

Robert.
 

Tom Pollok

unread,
Jan 15, 2020, 6:24:32 AM1/15/20
to OpenSceneGraph Users
Hello Robert,

to test it with my old osg version, i fixed the obj file such it does not contain any indices to normals anymore, as there are no normals.
This indeed helped loading the model, but no textures appear at all. Should it load the textures automatically due to the first line in the obj file being mtllib Data.mtl and the use of usemtl material_0 before the faces or do i need to take extra care when loading a textured model?

For loading, im using only:

osgDB::Options* opt = new osgDB::Options;
opt->setOptionString("noRotation");

osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(pathToObjFile, opt);

Best,
Tom

Voerman, L.

unread,
Jan 15, 2020, 7:00:41 AM1/15/20
to osg-...@googlegroups.com, OpenSceneGraph Users
Hi Tom,
Your model works with texture for me, in osg 3.4.0 as well as 3.6.5 with the following commands:
sed -E "s#(f [0-9]+/[0-9]+)/0 ([0-9]+/[0-9]+)/0 ([0-9]+/[0-9]+)/0#\1 \2 \3#" "Data2.obj" > noNormals.obj
osgviewer -O noRotation  noNormals.obj
Laurens.


--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/b55a82c5-4801-49da-b1c4-149d868bd6fa%40googlegroups.com.
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Tom Pollok

unread,
Jan 15, 2020, 7:47:26 AM1/15/20
to OpenSceneGraph Users
Hi Laurens,

thank you for clarification! My problem was that im using openscenegraph in combination with osgEarth. I figured out how to fix it, so in case other osg and osgEarth users might run into the same issue.

To fix the issue i had to include

#include <osgEarth/Registry>

and after loading the model i had to run the shader generator on the model.

osgEarth::Registry::shaderGenerator().run( model );

Now everything works fine.

Thank you very much for your super quick help @Laurens and @Robert !!!

Best,
Tom
To unsubscribe from this group and stop receiving emails from it, send an email to osg-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages