Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
This is the code (simplified), the crash happend on line 49. I give some explainations after.
Expand|Select|Wrap|Line Numbers
- //-------------------------------------------------------------
- class MyBaseClass
- {
- //...
- };
- //-------------------------------------------------------------
- class MyInterface
- {
- public:
- virtual void OnTrigger(NxActor* actor1, NxActor* actor2) = 0;
- };
- //-------------------------------------------------------------
- class MyClass : public MyBaseClass, public MyInterface
- {
- public:
- MyClass();
- void OnTrigger(NxActor* actor1, NxActor* actor2); // called from a subsystem
- // when an event is raised.
- private:
- NxActor* m_actor;
- }
- //-------------------------------------------------------------
- MyClass::MyClass()
- {
- m_actor = CreateActor(); // create an actor for a particular sub system
- // (PhysX)
- m_actor.userData = this; // hold the instance pointer to have a 1:1
- // mapping between my instance and the actor
- // (userData is a void*)
- }
- //-------------------------------------------------------------
- void MyClass::OnTrigger(Actor* actor1, Actor* actor2)
- {
- }
- //-------------------------------------------------------------
- // The subsystem event callback
- //-------------------------------------------------------------
- void OnSubSystemTrigger(NxActor* actor1, NxActor* actor2)
- {
- if (actor1.userData)
- {
- MyInterface* obj = (MyInterface*) actor1.userData; // cast
- obj->OnTrigger(actor1, actor2); // Call the method.Here is the crash
- }
- }
- Just after the cast, obj is not valid "inside". When I use the VStudio watch on <MyInterface* obj> (line45) I get messy values :
Expand|Select|Wrap|Line Numbers
- - MyInterface obj 0x0055c108
- - MyClass
- - MyBaseClass
- __vfptr 0xfdfdfdfd *
- - MyInterface
- - _actor 0x00000065 {userData=??? } NxActor *
- And finally I get no error if iswitch the inheritance order from :
class MyClass : public MyBaseClass, public MyInterface
to :
class MyClass : public MyInterface, public MyBaseClass
Any idea ?
Thanks!