Recurring but random corruption of a SerializedNavmesh

Currently using version 5.3.1 with Unity 2022.3.30f1

My project is essentially a dungeon crawling game, where each dungeon “chunk” is a prefab with a NavmeshPrefab component storing the scanned navmesh. Everything works fine except that there is a specific chunk which the SerializedNavmesh corrupts from time to time without a noticeable pattern.

One of the two possible errors will happen:

AssertionException: Assertion failure. Value was False
Expected: True
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <0652bf0e14024522b5c92574ad0ef550>:0)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at <0652bf0e14024522b5c92574ad0ef550>:0)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) (at <0652bf0e14024522b5c92574ad0ef550>:0)
Pathfinding.Graphs.Navmesh.TileMeshes.Deserialize (System.Byte[] bytes) (at ./Packages/com.arongranberg.astar/Graphs/Navmesh/TileMeshes.cs:141)
Pathfinding.NavmeshPrefab.DrawGizmos () (at ./Packages/com.arongranberg.astar/Core/Misc/NavmeshPrefab.cs:124)
Pathfinding.Drawing.DrawingManager.DrawGizmos (System.Boolean usingRenderPipeline) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:669)
UnityEngine.Debug:LogException(Exception, Object)
Pathfinding.Drawing.DrawingManager:DrawGizmos(Boolean) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:671)
Pathfinding.Drawing.DrawingManager:Submit(Camera, CommandBufferWrapper, Boolean, Boolean) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:703)
Pathfinding.Drawing.DrawingManager:SubmitFrame(Camera, CommandBufferWrapper, Boolean) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:554)
Pathfinding.Drawing.DrawingManager:ExecuteCustomRenderPass(ScriptableRenderContext, Camera) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:479)
Pathfinding.Drawing.AlineURPRenderPass:Execute(ScriptableRenderContext, RenderingData&) (at ./Packages/com.arongranberg.astar/Drawing/AlineURPRenderPassFeature.cs:25)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
IOException: Corrupted data ReadInternal
System.IO.Compression.DeflateStreamNative.CheckResult (System.Int32 result, System.String where) (at <e2bec1e2c81b42b3b2ee8a58b12808fc>:0)
System.IO.Compression.DeflateStreamNative.ReadZStream (System.IntPtr buffer, System.Int32 length) (at <e2bec1e2c81b42b3b2ee8a58b12808fc>:0)
System.IO.Compression.DeflateStream.ReadInternal (System.Byte[] array, System.Int32 offset, System.Int32 count) (at <e2bec1e2c81b42b3b2ee8a58b12808fc>:0)
System.IO.Compression.DeflateStream.Read (System.Byte[] array, System.Int32 offset, System.Int32 count) (at <e2bec1e2c81b42b3b2ee8a58b12808fc>:0)
System.IO.BinaryReader.FillBuffer (System.Int32 numBytes) (at <467a840a914a47078e4ae9b0b1e8779e>:0)
System.IO.BinaryReader.ReadInt32 () (at <467a840a914a47078e4ae9b0b1e8779e>:0)
Pathfinding.Graphs.Navmesh.TileMeshes.Deserialize (System.Byte[] bytes) (at ./Packages/com.arongranberg.astar/Graphs/Navmesh/TileMeshes.cs:122)
Pathfinding.NavmeshPrefab.DrawGizmos () (at ./Packages/com.arongranberg.astar/Core/Misc/NavmeshPrefab.cs:124)
Pathfinding.Drawing.DrawingManager.DrawGizmos (System.Boolean usingRenderPipeline) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:669)
UnityEngine.Debug:LogException(Exception, Object)
Pathfinding.Drawing.DrawingManager:DrawGizmos(Boolean) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:671)
Pathfinding.Drawing.DrawingManager:Submit(Camera, CommandBufferWrapper, Boolean, Boolean) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:703)
Pathfinding.Drawing.DrawingManager:SubmitFrame(Camera, CommandBufferWrapper, Boolean) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:554)
Pathfinding.Drawing.DrawingManager:ExecuteCustomRenderPass(ScriptableRenderContext, Camera) (at ./Packages/com.arongranberg.astar/Drawing/DrawingManager.cs:479)
Pathfinding.Drawing.AlineURPRenderPass:Execute(ScriptableRenderContext, RenderingData&) (at ./Packages/com.arongranberg.astar/Drawing/AlineURPRenderPassFeature.cs:25)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

AFAIK, there’s nothing unique about that chunk compared to any other chunk in the database. Once it is seen as corrupted, it will stay corrupted between restarts until a rescan. Upon rescanning of that chunk, there’s no data change in the serializednavmesh bytes asset after diffing it with the previous version. This happens randomly to that chunk only for some reason.

  • No navmeshcuts are used
  • There are recastnavmeshmodifiers present in each chunk, but they are all disabled outside of gameplay
  • This error happens in prefab mode too when gizmos is turned on.

Gonna tag @aron_granberg on this one- can you also upload the two chunks scanned navmesh, possibly even the prefabs themselves?

Hello, thanks for the reply. I have uploaded the files here.

Hi

Would it be possible for you to check if this still happens in a more recent version of Unity?

I can try for the sake of debugging, but I’m stuck with this version of unity officially. I’m going to try 2022.3.58f1.

The same errors happen in 2022.3.58f1 and 6000.0.38f1

No idea what that could be caused by.
And you are saying that the saved file doesn’t change at all?

Very strange.
Do you save the chunk files using the inspector, or using some custom script?

I checked the file you uploaded, and it definitely looks corrupt.

I added some logic to NavmeshPrefabEditor to allow me to invoke the “Scan & Save” button I would otherwise see in NavmeshPrefab on the Inspector tab.

And yeah, the save file did not change in every scan it. Post-scan, it is definitely behaving as if it is not corrupted because during runtime, the navmesh loads correctly. Until it suddenly decides that it is corrupted.

One theory I have is that the scanning process works fine, but when it comes to saving, the process may have corrupted somehow. No idea why it happens to that chunk, and only that chunk though.

You know there’s the NavmeshPrefab.ScanAndSaveToFile method?

Okay, I don’t remember why exactly I didn’t use that function, but now I’ve changed whatever I have to be using NavmeshPrefab.ScanAndSaveToFile instead. And I rescanned that room with that function. Still no change in the supposedly corrupted SerializedNavmesh file unfortunately.

Just as a sanity check. Do you think you could try the same thing on a different computer? And see if the file becomes corrupted there too?

Yeah, this has happened on at least 2 other PCs and is still happening right now when I checked.

Would it be possible for you to share a test scene in which I could replicate the issue?
I can already verify that the file is corrupt, but it would be interesting to be able to create a corrupt file myself.