Jump to content
  • Advertisement
Sign in to follow this  
tHomahwk

ifstream, floats, binary files, and release! oh my!

This topic is 4389 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 this weird error that appears solely on Release build (MSVC 2005, C++). I have a class that represents an Object in the game which I load from a binary file. This shouldn't matter, but just to give you more information; this binary file is created from a GUI editor that is created using C#. When loading this data from the binary file I am using ifstream. This class currently only contains 1 float type and when loading from this binary file in debug mode works perfectly fine. However, while in release this value always gets set with 0. This is how I am doing it: fin.read( (char*)pActor->m_fAttackRadius, 4 ); Is there something that I am doing wrong or there perhaps a better way that I should be loading this from the binary file? tHom.

Share this post


Link to post
Share on other sites
Advertisement
Does pActor->m_fAttackRadius have type float or type float* ?

If it's a float, you should use the address of operator eg:
fin.read( (char*)&pActor->m_fAttackRadius, 4 );

If it's a pointer to a float, you should make sure you allocated space for it.

HTH

Share this post


Link to post
Share on other sites
First off, although I doubt it'll solve your problem, your line should probably read:

fin.read( (char*)&(pActor->mfAttackRadius), sizeof( pActor->mfAttackRadius ) )

Don't rely on a hard-coded size for a type like that (the size of the type may change on different platforms, and you might change the type yourself later on). You were also missing the &, but I'm guessing that was a typo.

The sizeof operator is evaluated at compile time, so using a hard-coded value doesn't even give you a speed increase.

Does the file containing the binary data actually get opened successfully? Your working directory may be set differently in Release, and thus the application may be unable to find the file where it was looking in Debug.

Are there any features in your program that you only have turned on in debug mode? Could those affect deserialization?

Share this post


Link to post
Share on other sites
The variable is a float (not a float*), and the line should have the ampersand (yes it was a typo, as I was reading it from the laptop which was having problems connecting to the wireless :( ). I will try using the sizeof() operator in a few minutes and hope that it works.

Thanks for the help so far!

tHom

EDIT: The line now looks like this, but the float is still set to zero after this line is executed (checked via logger and the results from the game yeild that it is still 0):

fin.read( (char*)&(pActor->m_fAttackRadius), sizeof( pActor->m_fAttackRadius ) );

[Edited by - tHomahwk on October 18, 2006 11:10:41 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by tHomahwk
This class currently only contains 1 float type and when loading from this binary file in debug mode works perfectly fine. However, while in release this value always gets set with 0.


Beware that the debug and release executables are in different directories. Where is the file you are reading from?

Share this post


Link to post
Share on other sites
Quite true fruny, but I would suspect the OP checks (or should do) the file is open/valid.

typo in mod name oops.

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!