Urgent issue! : KeyNotFoundException on TileHandler crashes Unity!

I do sometimes get the following errors from time to time.

Not sure what can cause it but it seems to me like it is related to the carving?

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[Pathfinding.Poly2Tri.TriangulationPoint,System.Int32].get_Item (Pathfinding.Poly2Tri.TriangulationPoint key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
Pathfinding.Util.TileHandler.CutPoly (Pathfinding.Int3[] verts, System.Int32[] tris, Pathfinding.Int3[]& outVertsArr, System.Int32[]& outTrisArr, System.Int32& outVCount, System.Int32& outTCount, Pathfinding.Int3[] extraShape, Int3 cuttingOffset, Bounds realBounds, CutMode mode, Int32 perturbate) (at Assets/AstarPathfindingProject/Generators/Utilities/TileHandler.cs:848)
Pathfinding.Util.TileHandler+c__AnonStoreyC0.<>m__24 (Boolean force) (at Assets/AstarPathfindingProject/Generators/Utilities/TileHandler.cs:1340)
AstarPath.ProcessWorkItems (Boolean force) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:816)

Any ideas? Any directions to see where I can look for possible causes?

It definitly seems like it is being called on enabling some of my NavmeshCut objects.

I am not 100% sure, but I wonder if it is related to the 2 NavmeshCut components attached to the same gameobject? I have found one object that causes the above error and it has 2 NavmeshCut components on it.

Actually, and sadly, it was not related to any 2 NavmeshCut components attached to the same gameobject. Still not sure what it is, but it just happens while I was moving the NavmeshCut objects around. Worse still, when I do that for sometime and cause enough errors it even crashed Unity Editor!

I think this error is lot more serious than initially I thought, so it needs urgent attention.

Aron gone fishing? :stuck_out_tongue:

Has anyone heard from Aron recently?

This is really critical issue! Can Aron respond to this?

Oh God… now some spammer is spamming this site with craps! Where is Aron!

Hi

Sorry for not responding, I have been quite busy the last few days.

That error is a very rare error I have been trying to track down for some time. It is caused by a third party library adding new vertices sometimes for unknown reasons. I have tried several times to find out why it is happening, but I haven’t managed to solve it yet. Sorry.
It seem to be caused by floating point errors so if you try to move them around a bit I think that should solve it.
Make sure that no navmesh cut is “upside-down”, I think that might be might be able to cause it (it is not the root of the problem, because I have that fixed in a branch and it did not solve it completely, but maybe it reduced it a bit, I am not sure).

If nothing helps, could you possible send me a stripped down version of your project so that I could take a look at it and debug it.

PS: Yeah, the spammers are horrible. I haven’t managed to stop them even by switching out the captcha twice. At least it is better than the time when they posted several hundred pages of spam threads in just a few hours. I will clean it up.

humm… I am not sure what I can do to solve it… I don’t think the cut is “upside-down” and it happens a lot when I move them around too. I will try to create a simple scene … hopefully I can strip enough to be able to send it to you.

Just to make sure… is there way to catch the error and not actually crash the game/editor?

Hm, I guess if you cought the exception you could run this code:

catch (...) { CutPoly (verts, tris, ref outVertsArr, ref outTrisArr, out outVCount, out outTCount, extraShape, cuttingOffset, realBounds, mode, perturbate+1); return; }

That will just perturbate the navmesh cuts a bit (up to 10 times) to try to solve it.

I was able to not cause the error by making the cut size slightly bigger. But I got the feeling that I am just lucky and still don’t feel safe enough. I will try to catch the error some how.

I had look at the code line where it gives me the error, but I am not sure how I can catch the error in there to be able to prevent Unity from not crashing. You are saying it happens rarely,. but it happens a lots of times for me. Regardless of how many times it crashes the game, even if it does by once, it is not a good thing.

Can you help me to catch the error in question?

the line does a dictionary access like dict[x], change that to
try { something = dict[x]; } catch { CutPoly (verts, tris, ref outVertsArr, ref outTrisArr, out outVCount, out outTCount, extraShape, cuttingOffset, realBounds, mode, perturbate+1); return; }

I am not sure why it happens so often for you, I use navmesh cutting in another project with large worlds and hundreds of navmesh cuts per scene and I get that error like once every 2 weeks.

I have also found the case where two navmesh cut object’s corners are met exactly at the same places, it crashes Unity without warning or log. So in this case, there is no way for me to catch the error cause I don’t know where it is happening.

I will try to reproduce this in very simple scene and see if it happens again.

I have simple version of the crash scene which took me almost half day to make … :frowning:

Where can I upload it so you can take a look at it?

Also if I slightly change the test scene then I do get this “point on edge exception” log instead of outright crash, so just to let you know … it could be related to that?

It could also be related to the simple try and catch stuff I implemented to avoid crash this topic was originally created for,… but I don’t know.

Edit : I just reverted changes to the TileHandler.cs but it didn’t make any difference.

Send a PM.

Sorry that you had to use up so much time to create it.

The point on edge exception is caused by another limitation in a 3rd party library. I might be able to fix a few cases where it happens, but usually it is ok to just recurse and perturbe the obstacles a bit to avoid them touching each other.

Are you really getting a crash? As in, unity/the game closing down. In all cases that I get it, it is just an exception and the rest continues to work.

Yes, Unity and Game build just crashes out right and returns to desktop without any warning or logging. For some reason, google drive didn’t upload my test file from my work pc so I can’t send it to you right now, but I will do it first thing in the morning which is around 9 hours from now. We have some demo to build and we really want to avoid game crashing into desktop.

I also had exceptions before and I tried to change size of the cut boxes etc to get around the issue, but I still got the crash after having few of them happening in a seesion. Here is my observed behaviour :

  1. Gets a exception from one of the navmesh cut object.
  2. While moving that object with problematic navmesh cut object , I get the exceptions every now and then.
  3. With “enough” exceptions caused, it crashes Unity WITH send crash report.
  4. I also have particular case where I don’t move any navmesh cut objects but upload loading a scene, it crashes out right into the desktop without crash report. This is case where I have a particular set of colliders for wall and two navmesh cut objects near to each other having one of their corners seems like “touching” each others corner. (example scene that I will send)

And just jigging and moving the cut navmesh objects around to avoid the crash case is not an option, because it can happen again as the levels are built with tile like system and objects tends to also move around.