Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Neo Genesis10

Unexpected return values

This topic is 5243 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 have a function which returns an object pointer. Under debug I established that the item is in fact returned correctly (as in the return value is in fact the correct pointer). HOWEVER, the value which this return value is being assigned to ends up completely different. The line looks like this: value = Pointer_Return(...); Debug insists the return value is the pointer (double checked under Watch) and the 'value' variable becomes totally different. The only clue I have to this mystery is an error when it tries to access the non-existant object. Note that the return value is NOT NULL, so it bypasses all of my checking routines. Error message is "First-chance exception in Adventure.exe: 0xC0000005: Access Violation.". EDIT: The variable 'value' is a local variable so should not be affected by other routines as it is not passed by reference anywhere. Worship the holy trinity that is Blitz, Babes and Beers! [edited by - Neo Genesis10 on April 12, 2004 6:53:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
Fixed problem. Oddly enough, the memory my program was using was being altered by another function. Seems very strange to me, but the code now executes without problem...

Worship the holy trinity that is Blitz, Babes and Beers!

Share this post


Link to post
Share on other sites
Check WHAT you are returning. Maybe the pointer you are returning
is to a local variable, so after returning from your function that memory is released and that pointer points to something that is not there.

Share this post


Link to post
Share on other sites
Actually, the function which caused the problem was in fact a totally different application. I found it rather worrying, but after killing the app it works fine... very strange indeed.

Worship the holy trinity that is Blitz, Babes and Beers!

Share this post


Link to post
Share on other sites
>_<

it''s because the other application happened to be writing to that piece of (physical) memory, because it became available for use.

It became available for use because your program released it.

It did that (with 99% certainty) because it was on the stack. Don''t return pointers to things on the stack. The memory is *no longer yours* and the object is *no longer valid*. Your pointer points to nothing which is guaranteed to be anything in particular at all.

If you need your function to create an object, you should be new-ing it, and returning the pointer you get from the new. That puts it on the heap, where it won''t be ''reclaimed'' at the end of the function. Now the tricky part is keeping track of when it needs to be destructed and who''s responsible for doing that. (A good reason to use a GCd language instead.)

Share this post


Link to post
Share on other sites
I don''t know if it is the exact same problem, but I realised that the ATI Hydravision thing, or a part of it, caused access violations whenever a window was closed, in any program. If I turned off the desktop manager feature in Hydravision, the access violations went away.

Share this post


Link to post
Share on other sites

  • 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!