[PyQt] problem with abstract classes

Diez B. Roggisch deets at web.de
Sun Aug 12 15:20:28 BST 2007


Hi,

I'm in the process of wrapping the irrlicht 3d engine. So far, things 
have been working smoothly. However, now I stumbled over a problem that 
so far has not been willing to be disappearing, intensive gdb-use 
notwithstanding.

There is a pure abstract class in Irrlicht, IEventReceiver. It looks 
like this:

//! Interface of an object which can receive events.
class IEventReceiver
{
public:

	virtual ~IEventReceiver() {};

	//! called if an event happened. returns true if event was processed
	virtual bool OnEvent(SEvent event) = 0;
};

This class I wrapped in SIP this way:

    class IEventReceiver /Abstract/ {
%TypeHeaderCode
#include <IEventReceiver.h>
%End
        public:
      bool OnEvent(irr::SEvent event);
        };


Which seems to work fine. Now of course I'm having troubles subclassing 
this class in Python, which is the reason I created a dummy-implemntation

namespace irr {
   class PyIEventReceiver : public IEventReceiver {
   public:
     virtual ~PyIEventReceiver();
     bool OnEvent(SEvent event);
   };
};

It is declared in my SIP-file as this:

    class PyIEventReceiver : irr::IEventReceiver {


    public:
      bool OnEvent(irr::SEvent event);
    };

I can subclass this class in python, and my SEvent-marshalling-code 
works fine as well, as the following test-script shows:

class MyER(irrlicht.irr.PyIEventReceiver):
     def OnEvent(self, event):
         print event

er = MyER()

event = (irrlicht.irr.EET_MOUSE_INPUT_EVENT, 100, 100, .5, 1)
er.OnEvent(event)



But now if I set this IEventReceiver to my IrrlichtDevice, I get the 
following error (inside GDB):

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000008
0x0297119f in irr::CIrrDeviceStub::postEventFromUser (this=0x141a8f0, 
event={EventType = EET_MOUSE_INPUT_EVENT, {GUIEvent = {Caller = 0x145, 
EventType = 247}, MouseInput = {X = 325, Y = 247, Wheel = 0, Event = 
EMIE_MOUSE_MOVED}, KeyInput = {Char = 325, Key = KEY_CRSEL, PressedDown 
= false, Shift = false, Control = false}, LogEvent = {Text = 0x145 
<Address 0x145 out of bounds>, Level = 247}, UserEvent = {UserData1 = 
325, UserData2 = 247, UserData3 = 0}}}) at 
/Users/deets/Download/irrlicht-1.3.1/source/Irrlicht/MacOSX/../CIrrDeviceStub.cpp:164
164                     absorbed = UserReceiver->OnEvent(event);
(gdb) p UserReceiver
warning: RTTI symbol not found for class 'irr::NSOpenGLViewDeviceDelegate'
$1 = (IEventReceiver *) 0x1492ec0
Current language:  auto; currently c++

UserReceiver here is a pointer to a IEventReceiver, which seems to be 
correctly set. I tried stepping into the code, but wasn't able to.

This is with OSX 10.4, Python2.5, latest stable sip (4.7).

Any suggestions? Am I doing something fundamentally wrong wrt 
implementation of C++-interfaces?

Kind regards,

Diez



More information about the PyQt mailing list