1.) Make a trivial change to code, int x = 0;
2.) Save, unity recompiles
3.) Run the game in editor, works fine
4.) Stop the game in editor
5.) Run the game in editor again, exception thrown the first time it tries to pathfind:
ObjectDisposedException: The Unity.Collections.NativeList1[AnyPath.Graphs.SquareGrid.SquareGridCell] has been deallocated, it is not allowed to access it Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndBumpSecondaryVersion (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <cfc1ad890650411e946cff2e6f276711>:0) Unity.Collections.NativeList1[T].Add (T& value) (at Library/PackageCache/com.unity.collections@1.3.1/Unity.Collections/NativeList.cs:330)
AnyPath.Managed.Finders.Common.InStops2[TNode,TJob].AssignContainers (TJob& job) (at Assets/AnyPath/Managed/Finders/Common/InStops.cs:86) AnyPath.Managed.Finders.PathFinder6[TGraph,TNode,TH,TMod,TProc,TSeg].AssignContainers (AnyPath.Managed.Finders.PathFinder6+Job[TGraph,TNode,TH,TMod,TProc,TSeg]& job) (at Assets/AnyPath/Managed/Finders/PathFinder.cs:80) AnyPath.Managed.Finders.ManagedGraphJobWrapper4[TGraph,TNode,TJob,TResult].Schedule () (at Assets/AnyPath/Managed/Finders/ManagedGraphJobWrapper.cs:121)
I have thoroughly scoured the code and I can’t find anything on my end that is disposing of anything before it should.
6.) Stop game again
7.) Runs fine from then on until a code change is made
This is one of the weirdest things I’ve ever seen so I’m hoping someone else has seen it or something like it. All of my other code seems to function normally, I added and started using the package recently, there were no similarly bizarre crash bugs before then.
The linked asset marks 2020.3.16f1 as the minimum requirement, your version 2020.3.14f1 is below that. That’s also far behind 2020.3.48f1, the final release in the 2020.3 cycle. 2020.3 is out of support as well. Update to 2022.3 if possible. 2020.3 (and soon 2021.3) is no longer supported and doesn’t get fixes.
This is a paid asset, so the usual pattern of inspecting the source code to see what was wrong is hard for others. Try contacting the asset publisher for support.
Fair point, I did not realize I was step below the required package. I did reach out to the asset owner and he has been responsive, but the particular nature of this bug made me think it was perhaps an editor bug instead of something specific to his code.
I am trying it with the latest editor version, I had not changed year versions because newer versions c# version removed the functionality I was using to serialize random seeds, but I will hack something together for now and see if it solves this particular issue.
This could be related to things like using statics and / or generally mishandling the order of significant operations (allocation / disposal / usage). Make sure lingering allocations are always cleaned up for every Play Mode session, usually by hooking a callback for play mode exit or OnDestroy.
There could also be errors when an operation like adding a collection element invalidates an existing view of some data, like an iterator used in a foreach loop. Make sure not to add/remove a collection in a way that causes allocation changes while it’s being used for an iterator etc. Allocator.Temp is especially problematic in this way, read this document.
If anyone finds this in the future, this was related to using statics to hold state while Domain Reload was turned off. AnyPath is being patched to fix the issue, a temporary fix is to turn Domain Reload back on.