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. Dismiss Notice

[Solved] A Native Collection has not been disposed, resulting in a memory leak.

Discussion in 'Entity Component System' started by Antypodish, Aug 31, 2018.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    So I have receiving none critical error at OnCreateManager () after NativeArray allocation.

    A Native Collection has not been disposed, resulting in a memory leak C:\User\ .....

    None critical, as code runs.

    To simplyfy

    Code (CSharp):
    1. // for now
    2. static public List <Nodes> octrees = new List <Nodes> () ;
    3.  
    4. public struct Nodes
    5. {
    6.     public int lastNodeIndex ;
    7.     public NativeArray <Bounds> bounds ;
    8.     ...
    9. }
    10.  
    11. protected override void OnCreateManager (int capacity)
    12. {
    13. NodesData octree = new NodesData () ;
    14. octree.bounds = new NativeArray<Bounds> ( 100, Allocator.Persistent ) ;
    15. ...
    16. // for now storing in the list
    17. octrees.Add ( octree ) ;
    18.  
    19. // If I try add dispose, it throws error (see spoiler for full description)
    20. // InvalidOperationException: The native container has been declared as [WriteOnly] in the job, but you are reading from it.
    21. octree.a_bounds.Dispose () ;
    22.  
    23. }
    InvalidOperationException: The native container has been declared as [WriteOnly] in the job, but you are reading from it.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) <0x1c7831c0 + 0x00052> in <f718fbf7147e402282fdacf37bdd8584>:0
    Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at C:/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:113)
    Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at C:/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:134)
    ECS.Octree.Point.BoundingOctreeAddNodeSystem._Add2RootNode (System.Int32 i_octreeIndex, System.Int32 i_nodeIndex, ECS.Octree.EntityInstance entityInstance, ECS.Octree.Bounds entityBounds) (at Assets/Project/Scripts/Octree/Systems/BoundingOctreeAddNodeSystem.cs:455)
    ECS.Octree.Point.BoundingOctreeAddNodeSystem._AddEntity (System.Int32 i_octreeIndex, ECS.Octree.EntityInstance entityInstance) (at Assets/Project/Scripts/Octree/Systems/BoundingOctreeAddNodeSystem.cs:418)
    ECS.Octree.Point.BoundingOctreeAddNodeSystem+AddNode.Execute () (at Assets/Project/Scripts/Octree/Systems/BoundingOctreeAddNodeSystem.cs:268)
    Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at C:/buildslave/unity/build/Runtime/Jobs/Managed/IJob.cs:30)

    Without dispose it works. However it throws errors at initialization, then let code run.
    What I am missing?
    [ReadOnly] ?

    Is the List an issue?
     
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    The dispose call has to be done when you close the application or have no more use for the bounds array in the octrees node list.

    if you dispose it right away you will get errors whenever you try to use the NodesData since the array is disposed.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    Ah ..
    Silly me. Thx lot.

    Added

    Code (CSharp):
    1. protected override void OnDestroyManager ( )
    2. {
    3. .. dispose calls
    4. }
    This solves the issue.
    So error was actually from previous simulation. Makes sense.
     
    MNNoxMortem and chris_gong like this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    I would like indicate one more thing upon that error message, since it came back, after migrating to latest Entities preview 11.

    It is more feature request.

    It would be nice, if such error ..

    A Native Collection has not been disposed, resulting in a memory leak. It was allocated at C:\Users\...\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.collections@0.0.9-preview.3\Unity.Collections\NativeList.cs:24.


    ... could point into a script, where the error is generated. I got multiple scripts in project with native arrays and not sure, where the error is called from. Had no errors before upgrade, so now I need check manually every possible location, where dispose may be missing.
     
  5. simonm_unity

    simonm_unity

    Unity Technologies

    Joined:
    Mar 21, 2018
    Posts:
    13
    I have it on my todo list to add an option to track the callstack of these allocations. That should make them easy to track down. I should be able to get to this soon!
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    Most of them have some hints (# line of code) to allow track them down. Or even double click works.
    But still having from to time, these which are hard to track down.

    Anyway, looking forward to an update.
    Thx
     
  7. PieterPaladin

    PieterPaladin

    Joined:
    Nov 25, 2015
    Posts:
    2
    Hi Simon,

    Do you know if there is any progress on this feature?

    Thanks!

    Pieter
     
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    With latest Entities 0.0.12 preview 20, error shows now the system *.cs file name and the job line.
    This is big help already. Thx @simonm_unity
    However, error do not indicates, which NativeArray may cause the problem.
    So if you have more than one array, this may become tedious to find source of issue.
     
  9. simonm_unity

    simonm_unity

    Unity Technologies

    Joined:
    Mar 21, 2018
    Posts:
    13
    Support for full stack traces is done (not by me) and should make it into 2019.1.
    So hopefully you should be able to use this soon.
     
  10. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    How do I enable the full stack trace on 2019.2.0a4? I get a bunch of "
    A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details." without any traces, just that line. Already tried enabling it from the console menu and player settings, even disabled burst but still the same.
     
    Zamaroht and learc83 like this.
  11. tree_fiddler_2000

    tree_fiddler_2000

    Joined:
    Dec 5, 2018
    Posts:
    15
    Any follow up from the above? I'm on 2019.1.0b4, can't see a way to turn it on... setting somewhere?
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Main Menu > Jobs > Leak Detection > Full Stack Traces (Expensive)
     
    Nutter, Ghosthowl, Ogham and 5 others like this.
  13. tree_fiddler_2000

    tree_fiddler_2000

    Joined:
    Dec 5, 2018
    Posts:
    15
    I don't seem to have that menu in 2019.1.0b4. I tried installing the jobs package (0.0.7) but it doesn't seem to compile on 2019.1.
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Try 2019.1.0b5.
     
    majedmadev likes this.
  15. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    That menu option comes with the Jobs package. Good luck finding the right combination of versions to make it compile. Wiping the shader and package cache does help sometimes.
     
    scarface117 likes this.
  16. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Thanks; I was looking for this!
     
  17. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    374
    Taken from another thread:
    https://forum.unity.com/threads/a-n...ry-leak-enable-full-stacktraces-to-ge.631198/

    if you are looking for the option and you only see Burst inside the Jobs menu, then you have to go to the package manager and install the Entities package, that has a lot of dependencies and will make the rest of the options visible (at least with 2019.4).

    After that you will see the Leak Detection options and the jobs debugger.
     
    Last edited: Aug 2, 2021
  18. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    254
    I don't think this is necessary anymore. With the latest burst, jobs and collections packages I get the options
     
  19. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,125
    I get
    I believe this is related to PlayFab.
     
    LostCaanan likes this.
  20. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    374
    Yep. You're right. It's working now.
     
  21. LostCaanan

    LostCaanan

    Joined:
    Dec 5, 2021
    Posts:
    1
    You're Right, I deleted Playfab in a copy of the Project and it fixed that issue.
     
    pKallv likes this.
  22. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    I just upgraded my project from Unity 2019 to 2021, and now I'm seeing this error. My project doesn't use any burst/job features (that I know of). I didn't see the full stack trace option so I installed the com.unity.entities package as I've seen recommended on various threads. However, that package throws a bunch of compiler errors. Not sure what to do. Screen Shot 2022-03-24 at 11.55.35 AM.jpg
     
  23. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Looks like your editor version is wrong; entities 0.50 only works on 20.3.30+. 0.51 will work on 2021.
     
  24. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    I don't see a version 0.51. 0.50 is the latest version that was released on March 16, 2022.
    I saw another thread from about 2 years ago where someone said that they needed to improve the whole issue because it's silly to require a package to debug a core issue. Apparently that never happened?
     
  25. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    What elliotc was trying to say is that u need to update the unity editor to 2020.3.30, anything lower won't work.
    Entities 0.51 has not been released yet and there's no ETA.

    I do agree on the frustration with unity versioning and the packages.
     
  26. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    But I'm already using Unity 2021.2.16f1 (I just started using it). The issue never appeared in Unity 2020.3.7f1.
     
  27. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    Yup, because 2021 is not supported yet. Only 2020.3.30 up to 2020.3.XX. nothing else (at least not officially).
    I guess unity has a couple of big clients using latest 2020 and ECS cuz otherwise, this 0.50 release makes little sense.
     
    iwillbenice likes this.
  28. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    @elliotc-unity
    Ok... what should I do to deal with these errors in Unity 2021? I have a feeling they're coming from the Unity engine, because my code doesn't use any native collections. I can't tell where they're coming from without a full stack.
     
  29. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    I think your packages repo is corrupted or something, your errors are related to ECS and burst, but if this screenshot you posted in the other thread is from the same project, you shouldn't have any of those packages installed.

     
  30. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    Yes, it's the same project. What do you mean I shouldn't have any of those packages installed? Do you mean the ones listed that are actually installed? Or the burst one? Here's the contents of the manifest.json file:

    {
    "dependencies": {
    "com.onesignal.unity.android": "3.0.0-beta.6",
    "com.onesignal.unity.core": "3.0.0-beta.4",
    "com.onesignal.unity.ios": "3.0.0-beta.6",
    "com.unity.2d.animation": "7.0.4",
    "com.unity.2d.psdimporter": "6.0.3",
    "com.unity.2d.sprite": "1.0.0",
    "com.unity.analytics": "3.6.12",
    "com.unity.ide.rider": "3.0.12",
    "com.unity.ide.visualstudio": "2.0.14",
    "com.unity.ide.vscode": "1.2.5",
    "com.unity.mobile.android-logcat": "1.2.3",
    "com.unity.purchasing": "4.1.3",
    "com.unity.test-framework": "1.1.31",
    "com.unity.textmeshpro": "3.2.0-pre.3",
    "com.unity.timeline": "1.6.4",
    "com.unity.ugui": "1.0.0",
    "com.unity.xr.legacyinputhelpers": "2.1.9",
    "com.unity.modules.ai": "1.0.0",
    "com.unity.modules.androidjni": "1.0.0",
    "com.unity.modules.animation": "1.0.0",
    "com.unity.modules.assetbundle": "1.0.0",
    "com.unity.modules.audio": "1.0.0",
    "com.unity.modules.cloth": "1.0.0",
    "com.unity.modules.director": "1.0.0",
    "com.unity.modules.imageconversion": "1.0.0",
    "com.unity.modules.imgui": "1.0.0",
    "com.unity.modules.jsonserialize": "1.0.0",
    "com.unity.modules.particlesystem": "1.0.0",
    "com.unity.modules.physics": "1.0.0",
    "com.unity.modules.physics2d": "1.0.0",
    "com.unity.modules.screencapture": "1.0.0",
    "com.unity.modules.terrain": "1.0.0",
    "com.unity.modules.terrainphysics": "1.0.0",
    "com.unity.modules.tilemap": "1.0.0",
    "com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.umbra": "1.0.0",
    "com.unity.modules.unityanalytics": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestaudio": "1.0.0",
    "com.unity.modules.unitywebrequesttexture": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0",
    "com.unity.modules.vehicles": "1.0.0",
    "com.unity.modules.video": "1.0.0",
    "com.unity.modules.vr": "1.0.0",
    "com.unity.modules.wind": "1.0.0",
    "com.unity.modules.xr": "1.0.0"
    },
    "scopedRegistries": [
    {
    "name": "npmjs",
    "url": "https://registry.npmjs.org",
    "scopes": [
    "com.onesignal"
    ]
    }
    ]
    }
     
  31. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    You can't use 0.50 with 2021, period. It's broken six ways to sunday. You can't get there from here, or at least I don't know how you would. The work for 0.51 involves us a) making versions of the 0.50 packages that are friendlier to the 2021 situation, and b) landing stuff to a future patch release of 2021 that makes 2021 friendlier to the 0.50 (now 0.51) packages.

    Neither of those things are finished, which is why we haven't released 0.51. Moreover, reading internal tea leaves, it seems like 0.51 probably won't be compatible with 2020, either. So, if said tea leaves are correct, we'll have two streams of patch releases, one for 0.50, and one for 0.51, and never the twain shall meet.

    So, if you have to have 2021, you'll have to wait to use the new dots packages. Or, if you have to have the new dots packages, you'll have to wait to use 2021.
     
    hippocoder likes this.
  32. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    I only upgraded to 2021 to be more current and future-proof. I certainly didn't upgrade to use DOTS, or jobs, or AOT burst compiler, or any special feature at all. I upgraded my project from the existing 2020 project, and Unity did it's upgrade thing and I ended up with whatever Unity gave me. I never installed any additional packages, and I don't see any obvious additional packages installed in the package manager.

    So... I'm wondering if the native collection memory leak is a new thing, or if it's an old thing that's more verbal in 2021. Because I didn't change anything in the project between upgrading and seeing the messages. I was just trying to figure out how to troubleshoot the memory leak errors based on the errors' own suggestion, which is to enable full stacks. Though it doesn't give any instructions on how to do such a thing. If these memory leak errors are indeed a serious concern, then I would definitely like to get to the bottom of it, and so should Unity. If they're a false flag, then I guess I'll ignore them. I'm ignoring them for now since I can't seem to do anything about them, and they haven't yet created a fatal situation for my app.
     
    Neiist likes this.
  33. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    I think I understand at least part of what happened. Last August, @Darkgaze said to install the Entities package in order to get the leak checking menu, which was not correct. It happened to work, because com.unity.entities depends on com.unity.jobs, which is where that menu comes from, but com.unity.jobs is all you actually ever needed.

    So, at some point, you installed entities, and at some other point before or after that, you upgraded to 2021. But you never actually wanted or needed entities in your project, you were just confused by this thread.

    You could therefore try adding com.unity.jobs to your manifest, and you might just be fine. Alternately, you can just paste the code from the menu and run it yourself:


    const string kLeakOff = "Jobs/Leak Detection/Off";
    const string kLeakOn = "Jobs/Leak Detection/On";
    const string kLeakDetectionFull = "Jobs/Leak Detection/Full Stack Traces (Expensive)";

    [MenuItem(kLeakOff)]
    static void SwitchLeaksOff()
    {
    // In the case where someone enables, disables, then re-enables leak checking, we might miss some frees
    // while disabled. So to avoid spurious leak warnings, just forgive the leaks every time someone disables
    // leak checking through the menu.
    UnsafeUtility.ForgiveLeaks();
    NativeLeakDetection.Mode = NativeLeakDetectionMode.Disabled;
    Debug.LogWarning("Leak detection has been disabled. Leak warnings will not be generated, and all leaks up to now are forgotten.");
    }

    [MenuItem(kLeakOn)]
    static void SwitchLeaksOn()
    {
    NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
    Debug.Log("Leak detection has been enabled. Leak warnings will be generated upon exiting play mode.");
    }

    [MenuItem(kLeakDetectionFull)]
    static void SwitchLeaksFull()
    {
    NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
    Debug.Log("Leak detection with stack traces has been enabled. Leak warnings will be generated upon exiting play mode.");
    }


    Hope this helps!
     
  34. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    Well, I tried to install entities in 2021, but it just threw a bunch of errors, so I removed it. I never installed entities in 2020. I also never installed jobs, but I seem to have a menu related to jobs and several warnings & errors related to it. If I can remove it somehow, then I will. However, if I can't remove it then I'll try your menu options above. I'm actually very curious where the memory leaks are originating from anyway.
     
  35. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    I was able to manually add com.unity.jobs and get the menu item, thank you.
     
    skilani likes this.
  36. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    49
    Last edited: May 4, 2022
  37. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    49
  38. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    49
    Some suggestions to make this less painful:

    1. Have stack tracing options actually in the full stack tracing under build settings (see below)
    2. I thought full stack tracing referred to this - apparently not - so make the error message say exactly what the user has to do to enable it.
    upload_2022-5-6_11-38-24.png

    Hope this helps.
     
    skilani likes this.
  39. pevi

    pevi

    Joined:
    May 25, 2014
    Posts:
    3
    Hi.

    I dont know how to view the full stack trace. I activated options like Michael_Swan says, and i have a extended log:



    But empty with the native collection leak.

    I installed the collections package, but i dont find any named like "jobs". The menu jobs dont have any leak option.

    Any hint?
     
  40. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    You have to manually add the com.unity.jobs package in the package manager. Then you will get "Jobs" dropdown menu with "Leak Detection" submenu to turn it on or off or full stack.
    Screen Shot 2022-06-29 at 3.45.02 PM.jpg Screen Shot 2022-06-29 at 3.45.24 PM.jpg

    And yes, it's very silly that this has to be done. At least there should be a distinction between THESE stack traces and normal stack traces.
     
    Neiist likes this.
  41. pevi

    pevi

    Joined:
    May 25, 2014
    Posts:
    3
    Thanks Gillissie. Now i can see the leaks problem.

    Is was the request to the server in this line:

    Code (CSharp):
    1. request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
    I implement a dispose to the request when its finish and the leak problem dissapear.
     
  42. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Four years ago this was on the todo list. The error is exactly the same today - totally unhelpful. And I tried installing com.unity.entities via package manager (Unity 2021.3.2f1) and it gave loads of errors. Forced Unity to start in safe mode until I removed entities. So I can't get that stack trace turned on.
     
  43. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Hey thanks! This helped me solve my problem. Was a UnityWebRequest that I missed a Dispose on.
     
  44. NemanjaPavlovic

    NemanjaPavlovic

    Joined:
    Feb 25, 2022
    Posts:
    7
    if I try to dispose Native array that is persistent then its a error : NO NO you can not dispose persistent memory etc ...but if i don't i have memory leak .... what is problem in disposing this memory block ?
     
  45. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Please post the exact error and example code. You should be able to dispose it, it more sounds like you are trying to dispose the array twice.
     
    Anthiese likes this.
  46. NemanjaPavlovic

    NemanjaPavlovic

    Joined:
    Feb 25, 2022
    Posts:
    7
    Error was due the GPUReadBack was holding on to a data after delete on object is called , so i need to make sure that GPU is done whit it so i could call dispose on it .
     
    bb8_1 likes this.
  47. cwidisgroup

    cwidisgroup

    Joined:
    Sep 12, 2022
    Posts:
    2
    when I want to dispose the byteArray, I get this error message:
    ObjectDisposedException: The Unity.Collections.NativeArray`1[System.Byte] has been deallocated, it is not allowed to access it
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <88d854ea2c91426ebc464f01cd71aa85>:0)
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <88d854ea2c91426ebc464f01cd71aa85>:0)
    Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetUnsafePtr[T] (Unity.Collections.NativeArray`1[T] nativeArray) (at <88d854ea2c91426ebc464f01cd71aa85>:0)
    Cwipc.PrerecordedPointCloudReader.GetComputeBuffer (UnityEngine.ComputeBuffer& computeBuffer) (at Library/PackageCache/nl.cwi.dis.cwipc@959f2f9bec/Runtime/Scripts/PrerecordedPointCloudReader.cs:105)
    Cwipc.PointCloudRenderer.LateUpdate () (at Library/PackageCache/nl.cwi.dis.cwipc@959f2f9bec/Runtime/Scripts/PointCloudRenderer.cs:150)
    But if I don't dispose the byteArray, I got this erroe message:
    A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
    Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
    Cwipc.PrerecordedPointCloudReader:GetComputeBuffer(ComputeBuffer&) (at Library\PackageCache\nl.cwi.dis.cwipc@959f2f9bec\Runtime\Scripts\PrerecordedPointCloudReader.cs:100)
    Cwipc.PointCloudRenderer:LateUpdate() (at Library\PackageCache\nl.cwi.dis.cwipc@959f2f9bec\Runtime\Scripts\PointCloudRenderer.cs:150)

    what should I do with this? This happens when I want to display the point cloud sequences in the cwipc unity package, which is used to playback the point cloud.
    Thanks in advance
    upload_2022-12-27_23-43-24.png
     
  48. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    282
    Never post screenshots of code. Use code tags.
    The stack trace clearly indicates that you’re getting an exception accessing the data for a disposed collection. The shown code disposes the collection right after it has been created. This would be an error in this code. As it is written currently, it wouldn’t make sense to dispose the allocated buffer anyway, you’re allocating a buffer then throwing it away right after. The logic already disposes the collection that was referenced by byteArray, so the second dispose call seems to serve no purpose and should be removed.

    You must always ensure code paths leading to a memory access like GetUnsafePtr have a non-disposed collection when the access occurs.
     
    cwidisgroup likes this.