LodGenerator and UnsignedShort issue

I have been trying out the new LodGenerator and found an issue with certain meshes.

The index buffer of the mesh is of type Format.UnsignedShort. So when you retrieve the value in the gatherIndexData() method it can be negative (since Java has no “real” unsigned shorts).

Then on line 337 of the LodGenerator

[java] tri.vertex[i] = vertexLookup.get(tri.vertexId[i]);[/java]

The value of tri.vertexId[i] can thus be negative causing an index out of bounds exception on the vertexLookup list.

I would suggest adjusting the method to convert the UnsignedShort value to the actual value int value before line 337.

2 Likes

Also on a related topic, currently generating the LOD takes very long for large batched scenes. So I would prefer generating the LOD before batching them together, however the GeometryBatchFactory.makeLods() is completely commented out and the lod levels are discarded in the batching process.

Is there a reason why this code is commented out, is there an issue with it? (maybe I can look into)

<cite>@maximusgrey said:</cite> I have been trying out the new LodGenerator and found an issue with certain meshes.

The index buffer of the mesh is of type Format.UnsignedShort. So when you retrieve the value in the gatherIndexData() method it can be negative (since Java has no “real” unsigned shorts).

Then on line 337 of the LodGenerator

[java] tri.vertex[i] = vertexLookup.get(tri.vertexId[i]);[/java]

The value of tri.vertexId[i] can thus be negative causing an index out of bounds exception on the vertexLookup list.

I would suggest adjusting the method to convert the UnsignedShort value to the actual value int value before line 337.

Ohhh this could explain some problems part of my models have, I never investigated so far, since I assumed that the models simply had errors might be worth a look if its this issue.

Thanks for the issue report, I’ll take care of it.

About the lods in the geometry batch factory, idk why it’s commented, I remember, @rickard posted it a long time ago, maybe it has since be commented because it was causing issues…

Confirmed, the model causing problmes seems to use a ShortBuffer for indices.

I posted fixes for lods, here:
http://hub.jmonkeyengine.org/forum/topic/geometrybatchfactory-fixes/

It’s possible the ShortBuffer issue still exists in that code. I have a vague memory of running into it myself a couple of months ago.

1 Like

Thxs for the feedback!

@rickard I have used your fix and it works!

There are however some small issues remaing, (short vs Int and not all models have the same amount of LOD levels generated which is required for the batching). I’ll look into that tomorrow!

The original issue should be fixed.
I tested it with my models and it works, but since I never had the issue before, could you please test it with your problematic model?
I guess you need a model with more than 32767 vertices.

@rickard, i applied the patch in my local copy but there are also issues with int and short buffers, so I’ll fix it and commit later. Thanks for the patch.

@nehon, sorry for the delay, I am currently in New York for our company, but next week I will test the problematic model back in the Netherlands.

no rush, don’t worry

Oh hey, missed the post,

I will test as soonnas possible, but since I curenty change a bit c++ stuff for bullet I’m to scared to update the svn till its finsihed :slight_smile: