Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Unity Crash due to Newing object from library

Discussion in 'Editor & General Support' started by clbartlett, Oct 11, 2023.

  1. clbartlett

    clbartlett

    Joined:
    May 10, 2022
    Posts:
    8
    So much going on here so some background, we just updated from 19 to 22. The code has little to no change other than what occurred during the build in upgrade.

    We have a library (GDAL) which is used to create geometry and track it in a Database. I read from a file and based on the input create 1000s of objects.

    geo = new Geometry(wkbGeometryType.wkbPoint25D);

    Depending on the number of objects that get read in and created, Unity crashes when I stop playing or sometimes just outright crashes after finishing with the load.(More objects quicker the crash) From the crash log it occurs in a number of places usually with some sort of null reference inside unity code.

    In 2019 this code was called and there was never a problem. (Non Game project operating for years). But since the upgrade to 22 it crashes. I believe I have isolated it down to at least this creation of objects.
    If I load but do nothing with the objects it crashes, if I load but skip the new and don't do anything else it doesn't crash.
    Is there something that I am unaware of that needs done to update the library? This feels like a c++ error where I lost ptrs and overwrote memory in another part of code and am seeing the results later.

    Any ideas where to look or what to consider are appreciated. I just don't understand how this library and its calls work in 2019 but crash unity in 2022.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,106
    What Unity version? Be sure to try the latest patch release.
    What is the actual callstack? Sometimes this provides pointers, sometimes it may even hint at a known issue.
    Deleting the Library may also help with the odd unexplicable issue.
     
  3. clbartlett

    clbartlett

    Joined:
    May 10, 2022
    Posts:
    8
    We are on the latest Version, have deleted the Library and rebuild. The two most common callstacks are :

    NullReferenceException: Object reference not set to an instance of an object
    at (wrapper stelemref) System.Object.virt_stelemref_sealed_class(intptr,object)
    at System.Collections.Generic.Dictionary`2+ValueCollection[TKey,TValue].CopyTo (TValue[] array, System.Int32 index) [0x0005b] in <787acc3c9a4c471ba7d971300105af24>:0
    at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x0003b] in <787acc3c9a4c471ba7d971300105af24>:0
    at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00018] in <dab7f68612224ba3ae40f651d44f9d4c>:0
    at UnityEditor.GameView.DoToolbarGUI () [0x00060] in <fe7039efe678478d9c83e73bc6a6566d>:0
    at UnityEditor.GameView.OnGUI () [0x00053] in <fe7039efe678478d9c83e73bc6a6566d>:0
    at UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) [0x0005a] in <fe7039efe678478d9c83e73bc6a6566d>:0
    at UnityEditor.DockArea.DrawView (UnityEngine.Rect dockAreaRect) [0x00001] in <fe7039efe678478d9c83e73bc6a6566d>:0
    at UnityEditor.DockArea.OldOnGUI () [0x0019a] in <fe7039efe678478d9c83e73bc6a6566d>:0
    at UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) [0x00291] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) [0x000c4] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () [0x00068] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) [0x000e9] in <79c7b132c51745cbae03eebea8111c0e>:0
    Rethrow as ImmediateModeException
    at UnityEngine.UIElements.UIR.RenderChain.Render () [0x0011f] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.UIRRepaintUpdater.Update () [0x000c0] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) [0x0001e] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.Panel.UpdateForRepaint () [0x00035] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) [0x00078] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) [0x00051] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) [0x0003d] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) [0x0001a] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) [0x00001] in <79c7b132c51745cbae03eebea8111c0e>:0
    at UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) [0x00010] in <69483bb8da2444acb7ff79facafdfbf3>:0



    and

    =================================================================
    Native Crash Reporting
    =================================================================
    Got a UNKNOWN while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.
    =================================================================

    =================================================================
    Managed Stacktrace:
    =================================================================
    at <unknown> <0xffffffff>
    at System.Array:ClearInternal <0x000d6>
    at System.Array:Clear <0x002e2>
    at System.Collections.Generic.Dictionary`2:Clear <0x000ca>
    at UnityEngine.EventSystems.PointerInputModule:ClearSelection <0x00352>
    at UnityEngine.EventSystems.StandaloneInputModule:DeactivateModule <0x000ba>
    at UnityEngine.EventSystems.EventSystem:OnDisable <0x00165>
    at System.Object:runtime_invoke_void__this__ <0x00187>
    =================================================================
    Received signal SIGSEGV
    Obtained 30 stack frames
    0x0000020246d9dbb7 (Mono JIT Code) (wrapper managed-to-native) System.Array:ClearInternal (System.Array,int,int)
    0x0000020246d9da63 (Mono JIT Code) System.Array:Clear (System.Array,int,int)
    0x00000203d277e3cb (Mono JIT Code) System.Collections.Generic.Dictionary`2<int, UnityEngine.EventSystems.PointerEventData>:Clear ()
    0x00000203d277d6f3 (Mono JIT Code) UnityEngine.EventSystems.PointerInputModule:ClearSelection () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/PointerInputModule.cs:404)
    0x00000203d277d24b (Mono JIT Code) UnityEngine.EventSystems.StandaloneInputModule:DeactivateModule () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:267)
    0x00000203a19c7d96 (Mono JIT Code) UnityEngine.EventSystems.EventSystem:OnDisable () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:466)
    0x00000204006c4f08 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007ffed8f0e274 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    0x00007ffed8e4eb74 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    0x00007ffed8e4ed0c (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3113)
    0x00007ff6c0529d14 (Unity) scripting_method_invoke
    0x00007ff6c0507e34 (Unity) ScriptingInvocation::Invoke
    0x00007ff6c0507f1e (Unity) ScriptingInvocation::InvokeChecked
    0x00007ff6c05abde6 (Unity) SerializableManagedRef::CallMethod
    0x00007ff6c04fa382 (Unity) MonoBehaviour::RemoveFromManager
    0x00007ff6bfe5dfc5 (Unity) GameObject::ActivateAwakeRecursivelyInternal
    0x00007ff6bfe5db89 (Unity) GameObject::ActivateAwakeRecursively
    0x00007ff6bfe60d49 (Unity) GameObject::Deactivate
    0x00007ff6c018ba72 (Unity) DestroyObjectHighLevel_Internal
    0x00007ff6c018b694 (Unity) DestroyObjectHighLevel
    0x00007ff6c0196a1e (Unity) DestroyWorldObjects
    0x00007ff6c1468a3c (Unity) EditorSceneManager::RestoreSceneBackups
    0x00007ff6c1163b6f (Unity) PlayerLoopController::ExitPlayMode
    0x00007ff6c1173cd1 (Unity) PlayerLoopController::SetIsPlaying
    0x00007ff6c1177390 (Unity) Application::TickTimer
    0x00007ff6c15ee16a (Unity) MainMessageLoop
    0x00007ff6c15f39d0 (Unity) WinMain
    0x00007ff6c29d7dbe (Unity) __scrt_common_main_seh
    0x00007fff97007344 (KERNEL32) BaseThreadInitThunk
    0x00007fff985426b1 (ntdll) RtlUserThreadStart
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,106
    I've seen this in another user's report a few days ago. The callstack also indicated that it was going through GUI and ended up there.

    This may simply be a Unity bug, best to report this.
    Or something that mucks with Unity - I've had that at one point where I destroyed objects sometime in OnRender or one of the other "late" event methods that caused random crashes in selection outline drawing, until I figured out that, of course, I cannot just pull the rug (destroying possibly selected objects) while the renderer may have already cached an internal list of objects to work on. Like in your case, that behaviour changed between Unity versions.

    For now you could check if the issue goes away if you do not have certain windows open or objects selected (=> Inspector). Or check for a test if 2022.3.0 works without the crash and if so, try to find the latest patch level without the crash. Or try 2023.1 ...
     
  5. clbartlett

    clbartlett

    Joined:
    May 10, 2022
    Posts:
    8
    Still happens with no windows open. We have migrated to different versions. 2021-2023 have the problem, 2019&2020 do not have the problem. Our guess is there is something different that occurs with garbage cleanup that is causing the error. Have you heard anything like this before?
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,106
    Not like this, but the incremental GC was added or made default somewhere in these versions.

    I have another hunch from another issue recently. Between 2019 and later the C# and .NET Framework changed, in fact you may actually targeting .NET Standard now and not .NET 4.5. So there is a difference in the backend implementation that could cause migration issues in rare scenarios.