Search Unity

Question [Barracuda] ComputeBuffer cannot disposed, built app will crash when move scene

Discussion in 'Barracuda' started by QuangVuCanvas, Apr 12, 2022.

  1. QuangVuCanvas

    QuangVuCanvas

    Joined:
    Dec 14, 2021
    Posts:
    3
    ※Problem:
    I using a project on Github link: https://github.com/wojciechp6/YOLO-UnityBarracuda,
    This project using Barracuda (version 0.7.0) combine with YOLOv2 Tiny to make object detection app,
    Everything okay but when I move to other scene, ComputeBuffer cannot disposed (see attached log image).
    When on UnityEditor that will be okay (can move to other scene) but in built app, it's will crash. (I tried Barracuda version 0.7.0 to 1.4.0 but same issue)

    My dispose code:
    Code (CSharp):
    1. public void Dispose()
    2. {
    3.         input.Dispose();
    4.         input.FlushCache();
    5.  
    6.         premulTensor.Dispose();
    7.         premulTensor.FlushCache();
    8.  
    9.         nn.Dispose();
    10. }
    (see more in attached file)

    ※Question:
    How can I dispose/release undisposed ComputeBuffer or some another way to make built app not crash when move to other scene after using Barracuda?
    Note: In development build mode, built app will not crash when move to another scene.

    Thanks for reading.
    upload_2022-4-12_9-6-25.png
     

    Attached Files:

  2. QuangVuCanvas

    QuangVuCanvas

    Joined:
    Dec 14, 2021
    Posts:
    3
    Fixed!
    Change to below code:

    Code (CSharp):
    1. public void Dispose()
    2. {
    3.         ops.ResetAllocator(false);
    4.         cpuOps.ResetAllocator(false);
    5.  
    6.         input.Dispose();
    7.         input.FlushCache();
    8.  
    9.         premulTensor.Dispose();
    10.         premulTensor.FlushCache();
    11.  
    12.         nn.Dispose();
    13. }