Jump to content
  • Advertisement

Archived

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

BradDaBug

What do you do when you have no idea why something doesn't work?

This topic is 6263 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 this game, and i''m trying to encapsulate Direct3D and OpenGL into this class so i can use either one to draw the graphics using the same function calls. anyway, WinMain is giving me fits. The game compiles and runs when I comment out this funtion that loads certain settings from a file, but when I put the function back, the game crashes at strange places. One place is where I copy the hwnd of the window into another global hwnd. Heres the code: winHInstance = hinstance; winHInstance is a global. hinstance is from the WinMain parameter list thing. So I comment that out. Further down, it crashes here: winclass.cbSize = sizeof(WNDCLASSEX); That code''s from where it fills in the Window Class. The LoadSettings() function has NOTHING to do with Windows, and is just standard C code! WHAT IS GOIN ON!?

Share this post


Link to post
Share on other sites
Advertisement
You''ve probably encountered a "typo-bug". In any case, noone can really help you unless you post some of the code around the statement.

You''ll probably find the solution on your own.

Share this post


Link to post
Share on other sites
If its not a long code, sometimes its good to just write it over.

"I''ve sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do''Urden

Share this post


Link to post
Share on other sites
HO! Whats this?!

OK, I''ve snipped out a piece of code that when uncommented, everything works great. Heres the little booger...

else if (strncmp(buffer, "SCREEN RES: ",12) == 0)
{
WriteLog("Parsing resolution...");
strcpy(secondbuffer,strchr(buffer, 58)+2);
WriteLog("Resolution: %s",secondbuffer);

sscanf(secondbuffer,"%n, %n, %n",&GfxWidth,&GfxHeight,&GfxDepth);
}

This is in a bigger if...then block. Each case represents whatever label the line has. This one has "SCREEN RES:" since nearly each label has a different data format, each one is handled seperatly in its own case.

"buffer" is a pointer to a string holding the current line its working with.

"secondbuffer" is another pointer to a string that the junk following the ":" goes into (the important part, in other words)

The line this piece of code is working with looks something like this: "SCREEN RES: 320, 200, 16" (minus the quotes)

It doesn''t do anything with these numbers except load them into variables. I could put -420, 32000, 1000 and it wouldn''t make any difference.

Remmember...this code doesn''t crash, but it seems to be causing other code to crash. Why?

Share this post


Link to post
Share on other sites
Sometimes a line isn''t properly terminated somewhere (and sometimes it''s actually legal!) Commenting out that segment might allow such a line to affect the parsing of the rest of the file. Then again, maybe not. Go over your source and look for proper line termination. Also remember that an ''else'' will be parsed with the closest preceding ''if'' statement unless nested in curly brackets.

Share this post


Link to post
Share on other sites
Awesome! I fixed it!

it turned out the "secondbuffer" wasn''t big enough to hold all those numbers. It took 12 characters to hold that string, and it was only 10 characters long.

I don''t get why it crashed it so far later down the road, but at least I fixed it!

Thanks a bunch for yall''s help. Most of the time I can eventually fix whatever''s going on by talking through it like this. It also helps me to stop pulling my hair out.

Share this post


Link to post
Share on other sites
Because of how memory protection works, it''s usually OK to overwrite a buffer by a few bytes. That is, until something else tries to use those few bytes, and they''ve been changed by your incorrect code...

If you must use static buffers for reading files (or anything, for that matter), I always like to make them 3 or 4 times bigger than I''d ever expect to need. In your case, make secondBuffer something like 128 (I also like to make them powers of two ). 128 bytes is not much, and it''ll be reclaimed when your function goes out of scope anyway.


codeka.com - Just click it.

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!