473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Run-Time Check Failure #0 ... on a method call

1
Here is the error I get after calling a method (described below) :

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
  1.  
  2. //-------------------------------------------------------------
  3. class MyBaseClass 
  4. {
  5.  //...
  6. };
  7.  
  8. //-------------------------------------------------------------
  9. class MyInterface
  10. {
  11.   public:
  12.     virtual void OnTrigger(NxActor* actor1, NxActor* actor2) = 0;
  13. };
  14.  
  15. //-------------------------------------------------------------
  16. class MyClass : public MyBaseClass, public MyInterface
  17. {
  18. public: 
  19.  MyClass();   
  20.  void OnTrigger(NxActor* actor1, NxActor* actor2);   // called from a subsystem 
  21.                                                      // when an event is raised.
  22.  
  23. private:
  24.   NxActor* m_actor; 
  25. }
  26.  
  27. //-------------------------------------------------------------
  28. MyClass::MyClass()
  29. {
  30.   m_actor = CreateActor();      // create an actor for a particular sub system
  31.                                 // (PhysX)
  32.   m_actor.userData = this;      // hold the instance pointer to have a 1:1
  33.                                 // mapping between my instance and the actor 
  34.                                 // (userData is a void*)
  35. }
  36.  
  37. //-------------------------------------------------------------
  38. void MyClass::OnTrigger(Actor* actor1, Actor* actor2) 
  39. {
  40. }
  41.  
  42. //-------------------------------------------------------------
  43. //  The subsystem event callback 
  44. //-------------------------------------------------------------
  45. void OnSubSystemTrigger(NxActor* actor1, NxActor* actor2)
  46. {
  47.    if (actor1.userData)
  48.    {
  49.        MyInterface* obj = (MyInterface*) actor1.userData;  // cast
  50.        obj->OnTrigger(actor1, actor2);   // Call the method.Here is the crash
  51.    }
  52. }
- I checked if the value of userData didn't change between the constructor and the call. It is the same (eg : 0x0055c108).

- 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
  1.    - MyInterface obj  0x0055c108
  2.      - MyClass
  3.        - MyBaseClass
  4.             __vfptr    0xfdfdfdfd    *
  5.        - MyInterface
  6.        - _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!
Dec 8 '07 #1
1 3851
weaknessforcats
9,208 Expert Mod 8TB
1) You are not calling your base class constructors in the MyClass constructor. That is, you need an intialization list where you call the base class constructors. The automatci calling of base class constructors has been disabled for multiple inheritance. This was done to prevent common base classes from having their constructors called multiple times.

2) Ditch that void*. A void* in C++ manes your calling a relci C function ir b) ytour design is screwed up.

3) You never cast in C++ as part of your normal coding style. If the C++ compiler cannot figure out your type, then you have real problems. If you need to be in charge of things, switch to C where nothing is done to help you.
Dec 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: James | last post by:
Hi, I would like to run a custom script on a linux box via a button on a php page (php webpage hosted on the same linux box). Is this possible? If so , can you give me a pointer in the right...
5
by: hakim | last post by:
Hi, I need some information ? How I can run my project (Php) on CGI. Thanks.
0
by: Pedro Werneck | last post by:
Hi, I don't know if I should ask this here or on an emacs group/list. If I choose wrong, please forgive me. I am trying to run pychecker on the current buffer on python-mode using the...
3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run filename >>>run filename.py >>>/run filename >>>/run...
8
by: Jonathan Polley | last post by:
I have one account on a WindowsXP machine that refuses to run IDLE (or any other python script that uses Tk). Other people can login to that PC and IDLE runs just fine, so it is not an...
0
by: Kyle | last post by:
To any who chose to provide an answer, or even any suggestions to this problem, I thank you greatly in advance. +200 pts. for any valid solutions. I am currently in the process of converting a...
12
by: Mactash | last post by:
Folks, I am trying just to run a simple asp commands in the Internet Explorer. ( I have windows XP) When I run this asp lines on ASP Matrix web server it is ok. But, when I run this on IIS...
4
by: SiuLoBow | last post by:
Hi, Is there anyway to detect the ActiveX control is able to run on the browser or not? After I installed the ActiveX control to my system, user sometimes switch the secruity setting to "not...
4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.