bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
680 stars 69 forks source link

tentative fix for stream creation issues #103

Closed ipelupessy closed 4 years ago

ipelupessy commented 4 years ago

this change in the order of the code fixes or at least alleviates #63 for me

to be honest I don't understand why it makes a difference...

bastibe commented 4 years ago

This... can't be true. Right?

But, thinking about this some more, could it be that the channelmap gets deallocated at some point, which is the real cause of the error? Perhaps saving it to self._channelmap instead of channelmap could solve the issue (by keeping it alive as long as the stream is alive)? If that helps, the same should probably be true for samplespec.

rikvanriel commented 4 years ago

I suspect the reason why this worked might be that the python garbage collector and allocator reuse freed objects in some order related to when they were freed and what their addresses are.

Moving the allocation up a little might leave the contents of the freed objects alone a little longer, just long enough they do not get overwritten by the time the new stream has finished getting set up.

bastibe commented 4 years ago

@rikvanriel is probably right. At any rate, his be44b6557d68147a5789f7174cf4880f2efe6901 should fix this issue properly.

ipelupessy commented 4 years ago

yea, in retrospect.. such change in behaviour after only moving around stuff should trigger a suspicion of a GC issue!

rikvanriel commented 4 years ago

But only in retrospect. This is the kind of bug that often requires inspiration by multiple people.