djfun / audio-visualizer-python

a little GUI tool to render visualization videos of audio files
Other
242 stars 58 forks source link

Fix #70 - Crash when exporting video in GUI mode #71

Closed tassaron closed 2 years ago

tassaron commented 2 years ago

I was finally able to fix the memory error which made the program crash during export.

Funnily enough, it was caused by the same problem I had encountered somewhere else in the code. If a QImage goes through a Qt Signal/Slot, you need to store a reference to it within Python-land or else PyQt thinks it can trigger garbage collection on the C++ side, which then causes a memory error the next time Python tries to access the object.

I really shot myself in the foot by not documenting this the first time, so I added explanatory comments. Haha.

This made the live preview unpredictable and unstable. The fact that it was inside a Python thread which was inside a QThread might not have helped. Python threads are pretty bad so I have to do some benchmarking to see if re-introducing the Python thread makes sense.

In this pull request I've also added a --no-preview commandline option. Exporting video will be faster without any preview, so it's worth including.