Search Unity

Unity freezes on second play after objects disposing

Discussion in 'Scripting' started by melanchall, Jul 29, 2019.

  1. melanchall

    melanchall

    Joined:
    May 25, 2018
    Posts:
    17
    I'm developing .NET library to work with MIDI files and MIDI devices – DryWetMIDI. I have the issue with playback on Unity: Playback produces unexpected results in Unity. User who reported the issue created a simple Unity project which illustrates the problem: DWM.Test2.zip.

    Steps to reproduce:
    1. Open and load the Unity project
    2. Edit Line 19 of test.cs to a MIDI file on your computer
    3. Press play. Allow the full MIDI file to playback. When it's done, "disposed!" will appear in the console.
    4. Press the play button to end the game. Press it again to restart, and Unity will crash.
    5. If you press the play button to stop the game before the file is finished, Unity will not crash, but will not playback the second time.
    I suppose it's related with disposing of output device and playback which hold unmnaged resources.
    Also I've tried to follow this article and removed all finalizers but it didn't solve the problem.

    Seems like there is a deadlock inside of Unity/Mono on objects cleanup. Can someone explain why this happens?