Question

I have a very odd Problem:

I use one of my base classes: IEventlistener() which gets implemented by many other classes. Most of the time the system works. But now a very strange problem occured.

Once class (CGUIService) implements the interface, one method (VGetListenerName) works as expected the other one (VHandleMessage) gets a pure call when I check the callstack and I don't understand why -.- (seems as if the vtable gets somehow overwritten or out of bounds ...)

I made a screenshot so you can see variable before I call the VHandleMessage, which of course leads to a debug assertion R6025 - pure virtual function call because somehow the implemented method isn't entered in the vtable of the IEventlistener().

Highres: www.fantasyhaze.com/cb/Error_purecall.png www.fantasyhaze.com/cb/Error_purecall.png

I hope someone can give me a hint :)

Edit1.)

So just to explain it a little bit more I have created a new screenshot which shows the same process, but now I have included 2 more virtual function which are not pure and have a implementation (becuase of time reasons, I have not the time to implement all methods again in each class which uses the interface)

The purple ones are the new ones, The red one is the one which does not work The orange one is the method which was there before and which worked and still works

You can see on the left side, that the VGetListenerName,VHandleEvent1,VHandleEvent2 work (debugpoint + current position) and that those 3 are in the vtable ... but not the important one (red)

highres: www.fantasyhaze.com/cb/Error_purecall2.png vtable problem 2

Edit2.)

SOLUTION:

The main problem was, that CGUIService inherites from IBase. To have access to the Service I used a Service Locator which stores each service. Therefore it performes a static_cast in the Instance Getters Service::GetServiceInstance() and a static_cast was also performed to store the service as IBase. But IEventListener was not implemented in IBase furthermore the Service was cast back to IBase witout IEventListener and the vtable wasn't ok. Now IBase implements IEventListener and it works because the static_cast casts IEventListener correctly :)

Thx for the hints guys :)

Was it helpful?

Solution

It is hard to judge from one screenshot, but from the information you gave my first guess would be a dangling pointer - perhaps you attempt to call the virtual method on an object which was already destroyed? Another possibility is the object is not completely constructed yet, but this is not very likely, as this would most likely needs some race condition in multiple threads.

This and other possibilities are listed in What can cause a pure virtual function call in C++? quite exhaustively.

OTHER TIPS

Often pure virtual call is caused by calling a virtual function on an already destroyed object. When an object is being destroyed every base class destructor sets the virtual table pointer to class's virtual table. If a function is pure virtual and does not have implementation, pure virtual call handler address is put in the virtial table.

purecall means that for whatever reason the class implementing an interface has less virtual functions than the interface it implements. This often happens when:

  • you add a method into an interface
  • use the new method in the caller
  • recompile the caller, but don't recompile the implementaion (or recompile the implementation and forget to re-link against it)

So it's likely a build process problem. Check that you recompile all your stuff the caller depends on and if necessary re-link the caller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top