Sign in to follow this  

Visual Studio C++ Release Build Issue

This topic is 2046 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'm working on an OpenGL game, but I'm guessing this is mostly a C++ issue. It loads in models in a class from files, storing the values of both the model and the corresponding material for each object in vectors and arrays. When I run the debug version, it runs and displays what I expect to display if I write the code correctly, however when I build a release version, the values of some of the material files get read funny because it displays the wrong colours and shading values.

This is the issue below:

[img]http://dl.dropbox.com/u/30381754/Game%20Dev/Issue.png[/img]

I'm running the professional/ultimate/paid-for version of Visual Studio 2010, I've repeatedly cleaned the solution, project and the release builds, I've also modified the files where the issue is notable and it has no effect.

Why does this happen and what can I do to fix it?

Share this post


Link to post
Share on other sites
Without seeing the code there is only so much other people can do to help you. Such as pointing out common causes to this issue.

- not defining default values for variables
- putting functions into debug only macros, such as asserts
- memory trampling

Share this post


Link to post
Share on other sites
[quote name='bullfrog' timestamp='1336356045' post='4937932']
Without seeing the code there is only so much other people can do to help you. Such as pointing out common causes to this issue.

- not defining default values for variables
- putting functions into debug only macros, such as asserts
- memory trampling
[/quote]

OK well since from comparing the images the issue involves loading material files, so for any more help I'll paste the code for loading in the material library file:


[CODE]
int MultiObjectModel::read_MaterialFile(string fileName) // reads in a textfile containing the relevent material data.
{
ifstream inFile;
inFile.open(fileName.c_str());

if (!inFile.good())
{
cerr << "Can't open material file" << endl;
return 1;
}
float ambiant[4];
float diffuse[4];
float specular[4];
float shininess;

int matCount = 0;

while (!inFile.eof())
{
string line;
getline(inFile, line);

if (line.length() > 2)
{
if (line.substr(0,6)=="newmtl" && specular[2] >= 0)
{
material mat = {{ambiant[0],ambiant[1],ambiant[2],ambiant[3]},{diffuse[0],diffuse[1],diffuse[2],diffuse[3]},{specular[0],specular[1],specular[2],specular[3]},shininess};
Mat.push_back(mat);
}
else if (line.substr(0,3)==" Ka")
{
int w = 0;
stringstream ss(line);
string space[5];

for (int i = 0; i < 5; i++)
{getline(ss,space[i], ' ');} //This getline function extracts each character from the stringstream up until a space is found.

w = sscanf_s(space[1].c_str(), "%f", &ambiant[0]);
w = sscanf_s(space[2].c_str(), "%f", &ambiant[1]);
w = sscanf_s(space[3].c_str(), "%f", &ambiant[2]);
}
else if (line.substr(0,3)==" Kd")
{
int w = 0;
stringstream ss(line);
string space[5];

for (int i = 0; i < 5; i++)
{getline(ss,space[i], ' ');} //This getline function extracts each character from the stringstream up until a space is found.

w = sscanf_s(space[1].c_str(), "%f", &diffuse[0]);
w = sscanf_s(space[2].c_str(), "%f", &diffuse[1]);
w = sscanf_s(space[3].c_str(), "%f", &diffuse[2]);
}
else if (line.substr(0,3)==" Ks")
{
int w = 0;

stringstream ss(line);
string space[5];

for (int i = 0; i < 5; i++)
{getline(ss,space[i], ' ');} //This getline function extracts each character from the stringstream up until a space is found.

w = sscanf_s(space[1].c_str(), "%f", &specular[0]);
w = sscanf_s(space[2].c_str(), "%f", &specular[1]);
w = sscanf_s(space[3].c_str(), "%f", &specular[2]);
}
else if (line.substr(0,3)==" Ns")
{
int w = 0;

stringstream ss(line);
string space[2];

for (int i = 0; i < 2; i++)
{getline(ss,space[i], ' ');} //This getline function extracts each character from the stringstream up until a space is found.

w = sscanf_s(space[1].c_str(), "%f", &shininess);
}
else if (line.substr(0,2)==" d")
{
int w = 0;

stringstream ss(line);
string space[2];

for (int i = 0; i < 2; i++)
{getline(ss,space[i], ' ');} //This getline function extracts each character from the stringstream up until a space is found.

w = sscanf_s(space[1].c_str(), "%f", &ambiant[3]);
w = sscanf_s(space[1].c_str(), "%f", &diffuse[3]);
w = sscanf_s(space[1].c_str(), "%f", &specular[3]);
}
}
}

material mat = {{ambiant[0],ambiant[1],ambiant[2],ambiant[3]},{diffuse[0],diffuse[1],diffuse[2],diffuse[3]},{specular[0],specular[1],specular[2],specular[3]},shininess};
Mat.push_back(mat);

cout << "Material Loaded\n" << endl;
inFile.close();
return 0;
}[/CODE]

What I'll also say is that I had this issue with another program I was working on, except it was the wrong texture being applied to the wrong file, however I was able to resolve this by changing the file names of the texture files. That could mean memory trampling is most likely, but changing the file names of the material files had no effect here.

Share this post


Link to post
Share on other sites
I'd start with setting

[color=#000088]float[/color][color=#000000] ambiant[/color][color=#666600][[/color][color=#006666]4[/color][color=#666600]];[/color]
[color=#000088]float[/color][color=#000000] diffuse[/color][color=#666600][[/color][color=#006666]4[/color][color=#666600]];[/color]
[color=#000088]float[/color][color=#000000] specular[/color][color=#666600][[/color][color=#006666]4[/color][color=#666600]];[/color]
[color=#000088]float[/color][color=#000000] shininess[/color][color=#666600];[/color]

to zero or something.

The lines

[color=#000088]if[/color] [color=#666600]([/color][color=#000000]line[/color][color=#666600].[/color][color=#000000]length[/color][color=#666600]()[/color] [color=#666600]>[/color] [color=#006666]2[/color][color=#666600])[/color]
[color=#666600]{[/color]
[color=#000088]if[/color] [color=#666600]([/color][color=#000000]line[/color][color=#666600].[/color][color=#000000]substr[/color][color=#666600]([/color][color=#006666]0[/color][color=#666600],[/color][color=#006666]6[/color][color=#666600])==[/color][color=#008800]"newmtl"[/color] [color=#666600]&&[/color][color=#000000] specular[/color][color=#666600][[/color][color=#006666]2[/color][color=#666600]][/color] [color=#666600]>=[/color] [color=#006666]0[/color][color=#666600])[/color]
[color=#666600]{[/color]
[color=#000000]material mat [/color][color=#666600]=[/color] [color=#666600]{{[/color][color=#000000]ambiant[/color][color=#666600][[/color][color=#006666]0[/color][color=#666600]],[/color][color=#000000]ambiant[/color][color=#666600][[/color][color=#006666]1[/color][color=#666600]],[/color][color=#000000]ambiant[/color][color=#666600][[/color][color=#006666]2[/color][color=#666600]],[/color][color=#000000]ambiant[/color][color=#666600][[/color][color=#006666]3[/color][color=#666600]]},{[/color][color=#000000]diffuse[/color][color=#666600][[/color][color=#006666]0[/color][color=#666600]],[/color][color=#000000]diffuse[/color][color=#666600][[/color][color=#006666]1[/color][color=#666600]],[/color][color=#000000]diffuse[/color][color=#666600][[/color][color=#006666]2[/color][color=#666600]],[/color][color=#000000]diffuse[/color][color=#666600][[/color][color=#006666]3[/color][color=#666600]]},{[/color][color=#000000]specular[/color][color=#666600][[/color][color=#006666]0[/color][color=#666600]],[/color][color=#000000]specular[/color][color=#666600][[/color][color=#006666]1[/color][color=#666600]],[/color][color=#000000]specular[/color][color=#666600][[/color][color=#006666]2[/color][color=#666600]],[/color][color=#000000]specular[/color][color=#666600][[/color][color=#006666]3[/color][color=#666600]]},[/color][color=#000000]shininess[/color][color=#666600]};[/color]
[color=#660066]Mat[/color][color=#666600].[/color][color=#000000]push_back[/color][color=#666600]([/color][color=#000000]mat[/color][color=#666600]);[/color]
[color=#666600]}[/color]

could already access specular[2] (and all other color variables) without having been initialized properly and pointing to random garbage. Edited by Endurion

Share this post


Link to post
Share on other sites
You are not initialising your ambient,spec,... arrays. In debug mode , uninitialised variables will receive debug information, whereas in release mode the content of this variable is random.
Undefined behaviour can result whenever you access the variable before the got a value assigned, i.e. at this line:
[CODE]
if (line.substr(0,6)=="newmtl" && specular[2] >= 0)
[/CODE]
When your file stars with newmtl, it will most probably pass this condition, resulting in puhsing an undefined material on your material stack.

Try to initialise your four material variable(-arrays).

Share this post


Link to post
Share on other sites
Problem has been resolved! Now all those floats are initialised to NULL and I modified the if statement to prevent it passing on the first go. Thanks to both of you! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites

This topic is 2046 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this