dreamfairy / Unity-DynamicBone-JobSystem-Opmized

93 stars 29 forks source link

内存泄漏问题 #4

Open OtakuAndFitness opened 1 week ago

OtakuAndFitness commented 1 week ago

我用Unity2021.3.43f1打开运行,报错:

InvalidOperationException: The previously scheduled job DynamicBoneManager:FinalJob reads from the Unity.Collections.NativeList1[DynamicBoneBeta+Particle] FinalJob.ParticleInfo. You must call JobHandle.Complete() on the job DynamicBoneManager:FinalJob, before you can deallocate the Unity.Collections.NativeList1[DynamicBoneBeta+Particle] safely. Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <8814d6ed8fb84c9c8b81beb3efe22345>:0) Unity.Collections.LowLevel.Unsafe.DisposeSentinel.Dispose (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& safety, Unity.Collections.LowLevel.Unsafe.DisposeSentinel& sentinel) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/DisposeSentinel.cs:78) Unity.Collections.NativeList`1[T].Dispose () (at Library/PackageCache/com.unity.collections@1.5.1/Unity.Collections/NativeList.cs:521) DynamicBoneManager.OnDestroy () (at Assets/DynamicBoneManager.cs:484)

OnDestory中的释放资源似乎有问题

OtakuAndFitness commented 1 week ago

我把 JobHandle.ScheduleBatchedJobs();改成m_lastJobHandle.Complete()就会减少报错,但实例化很多个模型后,关闭运行并再次启动的时候还是会报错: A Native Collection has not been disposed, resulting in a memory leak. Allocated from: Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:58) DynamicBoneBeta:Awake() (at Assets/DynamicBoneBeta.cs:176) UnityEngine.GameObject:SetActive(GameObject, Boolean)

d__7:MoveNext() (at Assets/Respawn.cs:44) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Coroutines.cs:17) UnityEditor.EditorGUIUtility:RenderPlayModeViewCamerasInternal_Injected(RenderTexture, Int32, Vector2&, Boolean, Boolean) UnityEditor.EditorGUIUtility:RenderPlayModeViewCamerasInternal(RenderTexture, Int32, Vector2, Boolean, Boolean) UnityEditor.PlayModeView:RenderView(Vector2, Boolean) (at /Users/bokken/build/output/unity/unity/Editor/Mono/PlayModeView/PlayModeView.cs:228) UnityEditor.GameView:OnGUI() (at /Users/bokken/build/output/unity/unity/Editor/Mono/GameView/GameView.cs:983) UnityEditor.HostView:InvokeOnGUI(Rect) (at /Users/bokken/build/output/unity/unity/Editor/Mono/HostView.cs:464) UnityEditor.DockArea:DrawView(Rect) (at /Users/bokken/build/output/unity/unity/Editor/Mono/GUI/DockArea.cs:386) UnityEditor.DockArea:OldOnGUI() (at /Users/bokken/build/output/unity/unity/Editor/Mono/GUI/DockArea.cs:377) UnityEngine.UIElements.IMGUIContainer:DoOnGUI(Event, Matrix4x4, Rect, Boolean, Rect, Action, Boolean) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/IMGUIContainer.cs:357) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Matrix4x4, Rect, Action, Boolean) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/IMGUIContainer.cs:701) UnityEngine.UIElements.IMGUIContainer:DoIMGUIRepaint() (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/IMGUIContainer.cs:561) UnityEngine.UIElements.UIR.RenderChainCommand:ExecuteNonDrawMesh(DrawParams, Single, Exception&) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Renderer/UIRenderer/UIRenderers.cs:131) UnityEngine.UIElements.UIR.UIRenderDevice:EvaluateChain(RenderChainCommand, Material, Material, Texture, Texture, Single, NativeSlice`1, NativeSlice`1, MaterialPropertyBlock, Boolean, Exception&) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Renderer/UIRenderer/UIRenderDevice.cs:1035) UnityEngine.UIElements.UIR.RenderChain:Render() (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Renderer/UIRRenderChain.cs:500) UnityEngine.UIElements.UIRRepaintUpdater:Update() (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Renderer/UIRRepaintUpdater.cs:79) UnityEngine.UIElements.VisualTreeUpdater:UpdateVisualTreePhase(VisualTreeUpdatePhase) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/VisualTreeUpdater.cs:155) UnityEngine.UIElements.Panel:UpdateForRepaint() (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Panel.cs:1039) UnityEngine.UIElements.Panel:Repaint(Event) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Panel.cs:1091) UnityEngine.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:456) UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:211) UnityEngine.UIElements.UIEventRegistration:ProcessEvent(Int32, IntPtr) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:74) UnityEngine.UIElements.<>c:<.cctor>b__1_2(Int32, IntPtr) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:28) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)