MaKiPL / OpenVIII-monogame

Open source Final Fantasy VIII engine implementation in C# working on Windows and Linux (Android and iOS planned too!) [Monogame]
MIT License
637 stars 58 forks source link

Movie Audio Thread gets stuck in loop when exiting. #38

Closed Sebanisu closed 5 years ago

Sebanisu commented 5 years ago

When I exit while a video is playing the game doesn't quit. I pushed pause on the debugger and it was in the thread. since audio isn't playing the number of samples never changes so the loop goes on forever. I think to fix I might need to move the thread to ffcc class. So on dispose it kills the thread. Or I need to just kill the thread when I quit the game.

I think dispose is the better method. Though I was surprised it didn't throw an exception. :P

I'll put a fix in before my next pull request.

Sebanisu commented 5 years ago

hmm that's odd. dispose isn't called? I thought it would be called when I exit.

I guess that was simpler than I thought. per https://stackoverflow.com/questions/6062527/how-to-kill-thread-on-exit

If I put isBackground=true. Then it won't wait for it to end.

Albeoris commented 5 years ago

Therefore, if you need to stop the long-lived thread, the most correct way is to cancel the current operation and break the cycle. Most often for this purpose use CancellationToken. But in this case, the token becomes a synchronization context that needs to be dragged through all calls or stored in a shared field.

Sebanisu commented 5 years ago

--Edit-- Thanks for the information. I didn't know about tasks. I'm absorbing info about them now. I think I can use it for this instead of the thread. That will be my goal tonight.

Sebanisu commented 5 years ago

I have switched to a Task and added a cancellationtoken. Seems to work fine.

I have observed a new exception but it's rare and possibly unrelated to this. https://github.com/MaKiPL/OpenVIII/issues/47

I'm going to close this because this issue is no longer a problem. Thank you for the help :)