[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] PATCH: pyportmidi object de-allocation error (and fix)



Hello,

Thank you very much for the patches.  I will review them and apply them to both the pygame repo, and the portmidi repo.  The python bindings now live with portmidi, so no need to send them to the bitbucket page.

Cheers!

On 25 Feb 2011 18:10, "Christopher Arndt" <chris@xxxxxxxxxxxxx> wrote:
> Hi all,
>
> this has been bugging me for some time but now I finally found the time
> to look into this thoroughly: each time when using pygame.midi on
> Ubuntu, I got a BadPointer error when closing an Input or Output
> instance or when the program ends:
>
> >>> from pygame import midi
> >>> midi.init()
> >>> i = midi.Input(1)
> >>> i.close()
> PortMidi call failed...
> PortMidi: `Bad pointer'
> type ENTER...
>
> This was very annoying since apparently the Ubuntu version of
> libportmidi is a debug build, which will terminate the program with an
> error message whenever an error occurs in a portmidi call.
>
> So I compiled portmidi form source (SVN rev 222) and then pygame from
> SVN as well (I had to comment out the PORTTIME dependency in
> config_unix.py, since porttime is compiled into portmidi by default, but
> that is another problem.)
>
> But I still got the BadPointer errorr, only this time the exception was
> ignored. So I looked at pygame/lib/midi.py and pygame/src/pypm.pyx and
> found out what's wrong:
>
> <important part>
> pygame.midi.Input.close() calls pypm.Input.Close() and then sets
> self._input = None. This causes the pypm.Input instance, which was
> referenced by this attribute, to be garbage collected, which in turn
> causes pypm.Input.__dealloc__() to be called. This then tries to close
> the input device again unconditionally and this is where the error
> occurs since the pointer to the device is not valid any more, of course.
>
> The same error is presents in pygame.midi.Output / pypm.Output.
> </important part>
>
> I attached a minimal small patch which should fix this issue.
> Interestingly, part of the fix was already present in the code but
> commented out. After applying the patch (you may have to use the '-l'
> option with patch) pygame/src/pypm.c has to be rebuilt with Pyrex/Cython.
>
> Note: since I found that the pypm.pyx source is really a mess (source
> code formatting and other coding-style issues and also some programming
> inconsistencies) I did a bigger scope code cleanup, for which I have
> prepared a separate patch. I not sure which is the right place to submit
> this. Should I post this here or should I file a bug at
> https://bitbucket.org/aalex/pyportmidi ?
>
>
> Chris
>
>