Whinarn / UnityMeshSimplifier

Mesh simplification for Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash in GetSubMeshTriangles

Nostromo90 opened this issue · comments

Hello,

First Thanks for this very good and usefull development (and sorry for my English).

I know that it's huge but I have a mesh with 98500 SubMeshes (I don't know the triangles and vertices number).
When I Simplify it I have a crash in SubMeshesTriangles (Index out of bounds)
Is it possible for you to identify the reason?

My data is a CAD data which I cannot provide to you (confidential)

Hi!

I will try to look into it, but it would be good if you could also provide a stacktrace to the exception.

I could not find the reason for an index out of bounds, unless you don't use the ToMesh method and actually access GetSubMeshTriangles directly and provide a subMeshIndex that is out of range.

I did however do some additional work in the development branch: cb018de...0a74efc
I added some additional exception throwing and optimized the sub-mesh triangle offset calculation from calculating every time the method was accessed (which was 98500 times for you) to only once.

So please provide me with a stacktrace and it would be a lot easier to find out the cause of your problem.

Thanks!

meshsimplifier

Sorry for my late answer.
I change the code with your new code with Excepetion and here is the result that I have (not linked to your new exception)

Thank you for replying back with the exception details.

I have been able to replicate your issue along with another issue that was introduced with my latest work in the development branch.

I believe that this commit should resolve your issue: 8554037

Could you confirm if this fixes your problem? The work is still in the development branch. I will hold off to release it into the master branch until I know that this properly fixes your issue.

Thanks!

Hi,

On my screen you see that exception raised 3 times.
With this new version, I can pass 2 of them but for the last one I have no result (even on the simplifcation) (5 hours running on Xeon CPU E5 1630 v3 3 .7Ghz) and no result.
Any idea?

Hmm, I will have to look into it more. I don't have any more ideas at the time.
The exceptions looked the same, at the same line etc?

I'll have to hunt for more models to test with, and re-read the code again to see if I have missed something. I'll get back to you here once I know more or have a solution!

Hello again!

I know that this must be frustrating for you, since it takes you 5 hours in order to test it properly.
But I have made a commit adding assertions that should give more details: c0adc66

If you could test with that new code, that would be great. From the development branch again.
But I also have some further questions:

  1. Are you reusing a MeshSimplifier instance for several simplifications in a row? Or are they all separate instances?
  2. Have you tried debugging the code yourself? Because it's harder for me without access to the data (which I understand you cannot provide me).
  3. You mentioned that you have 98500 sub-meshes. Do you know if the exception that you are seeing is at the early indices or late indices (like the last few, or something)?
  4. With 98500 sub-meshes, how many triangles in total do you have? Could you please find out?
  5. Could you please provide me with the specific code section where you create and use the mesh simplifier? So that I can see how you are using the API.
  6. Are there any other exceptions in your project, related to UnityMeshSimplifier? Or are those index out of range exceptions the only ones you see?
  7. Now when you are using the new code, could you provide me the exceptions again? In case the line numbers have changed (they should have).
  8. What version of Unity are you using?

Thank you!

Hi,

I let it ran this night and got a result. It's only slow on this mesh.
Yesterday I ran decimation on several other mesh looks like the one with problem and all was running fine in a correct time (maximum 1 minutes per mesh) so I think you fix is ok and only one use case on my side cause problem of time.

For your questions:
1 I use only once Mesh simplifier with a quailty of 0.2
2 yes I try by adding some debug.log (my code is running in Thread and it's not always easy to debug in live (no problem detected
3 no I don't know the index
4 triangles is about 1 000 000 and about the same for vertices
5 I will add my code in next comment
6 No all other are perfect
7 No exception
8 Version 2018.1.1f1

Here is the code

//In the main call
UnityMeshSimplifier.MeshSimplifier ms = new UnityMeshSimplifier.MeshSimplifier(mesh);
System.Threading.Thread tmpThread = new Thread(() => DecimationThread(ref ms));
tmpThread.Start();
var start = DateTime.Now;
yield return new WaitWhile(() => tmpThread.IsAlive);
var end = DateTime.Now;
lock (sharedDecimatedMesh)
sharedDecimatedMesh.Add(rep.Id, ms.ToMesh());

//The thread of decimation (to avoid freeze of Unity during decimation)
private void DecimationThread(ref UnityMeshSimplifier.MeshSimplifier ms)
{
try
{
ms.SimplifyMesh(DecimationQuality);
}
catch (Exception ex)
{
Debug.LogError(ex.Message);
}
}

I have worked on some optimizations today that in some cases have a huge impact.
One of the car meshes that I test with used to run for about 10 minutes with the smart linking feature went down to 40 seconds after the optimizations.

So hopefully you might get some benefits from that. And again it's in the development branch for now.

And to confirm, there is still one model that is causing you this index out of range exception, or was that all resolved?