Jump to content
  • Advertisement
Sign in to follow this  
c0mas

Weird problem in C++ with .NET 2003

This topic is 4694 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've tryed to port one of my projects from Visual Studio 6 to Visual Studio .NET 2003. All went ok but when I've ran the project there were some crashes (apparently without any reason). All problems were somethilg like that:
class myClass
{
public:
.....
    inline int GetValue()         {return myValue;}
.....
protected:
.....
    int myValue;

}

.....
.....
 int a;
 myClass *cls = ... something valid
.....
 a = cls->GetValue();
.....
 
In the watch window myValue inside cls is ok, but a has some random data (most of the times 0xcdcdcdcd). I have lots of inline access functions but only a few are having this problem. The only solution was to remove the "inline" and to move the function's body into a cpp. Am I the only one with this problem ? Or anyone knows any little work around ? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
are you initializing myValue to something at startup? Debug mode does this for you, while release doesn't.

Share this post


Link to post
Share on other sites
Quote:
Original post by c0mas
In the watch window myValue inside cls is ok, but a has some random data (most of the times 0xcdcdcdcd).

That looks suspiciously like the default value that the debug release will set in order to catch uninitialized values. Sounds like you aren't calling a constructor, or else you aren't setting myValue within that constructor. More code would help clarify.

CM

Share this post


Link to post
Share on other sites
Yes, I initialize it and it happends on debug and release too.

In some cases (when I return a pointer) the value is not 0xcdcdcdcd, but a strange value.
Also I've tryed to make the member public and use it directly ... the same result.

One more failed try was to use:

inline void SetGetValue(int &val) {val = myValue;}


It only worked if I used:


static int g_myValue = 0;
.....
g_myValue = myValue; // somwhere in myClass
.....
extern int g_myValue;
.....
int a;
a = g_myValue;

Or if I move the function code inside a .cpp file (and remove the inline modifier).

Im sure that the value is set ok (the debugger shows me the right value, or if a make a trace within "cls" I get the right value). And of course rebuild all does not help.
Also I've tryed to see if it doesn't link with VC6 lib's (I've deleted them and relinked the project) same result.

Share this post


Link to post
Share on other sites
Try pasting a little more consistent code, for all we know you could be housing evil marsians inside those dots.

As the others said, 0xCDCDCDCD most commonly means that the variable has not been initialized, try explicitly setting it first and so on.

Share this post


Link to post
Share on other sites
As the others have said, try initializing

myValue

in the class constructor's initializer list.

Share this post


Link to post
Share on other sites
Well, it's not, unless that's the value you set it to.
Either that or it's not pointing to something that is valid anymore.

Share this post


Link to post
Share on other sites
Uuuuse the Debugger. See if the pointer is changing. If not, put a data breakpoint on mydata and see where it fires.

Share this post


Link to post
Share on other sites
Well, I've checked with the debugger.

cls it's ok and I can call any function in it. More than that, if I enter (with the debugger) in a cls->Function, myValue it's ok.

I've just realized that I have another thing to try: I'll check if the address(or offset from the address of cls) of myValue is the same.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!