python-sfml icon indicating copy to clipboard operation
python-sfml copied to clipboard

Recording with sf.SoundRecorder results in crash if stop() isn't maually called

Open intjelic opened this issue 9 years ago • 1 comments

When subclassing sf.SoundRecorder and we don't manually call stop() after start() was called, it results in segmentation fault.

Here's the code that reproduces the problem on Linux with Cython 0.24.

class MySoundRecorder(sf.SoundRecorder):
    def __init__(self):
        sf.SoundRecorder.__init__(self)

    def on_start(self):
        print("MySoundRecorder.on_start")
        return True

    def on_process_samples(self, samples):
        print("MySoundRecorder.on_process_samples")
        return True

    def on_stop(self):
        print("MySoundRecorder.on_stop")

input("Start recording")
sound_recorder = MySoundRecorder()
sound_recorder.start()
input("Press any key to stop recording")

The result is.

pure virtual method called
terminate called without an active exception
Aborted (core dumped)

However, if I add the line sound_recorder.stop(), the error message isn't displayed.

intjelic avatar May 13 '16 10:05 intjelic

After investigation, it results exactly when the internal C++ instance is destroyed.

    def __dealloc__(self):
        if self.p_soundrecorder is not NULL:
            print("aaa")
            del self.p_soundrecorder
            print("bbb")

The message "aaa" is printed, "bbb" isn't.

intjelic avatar May 13 '16 10:05 intjelic