• Announcements

Archived

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

The impossible-to-find bug

Recommended Posts

I am quite out of ideas about a little bug involving my vector graphics engine. Because it is a DD app, I can''t debug it using line-by-line stepping. If you tell me to get a monochrome monitor for debugging, plz be warned that I have no intention of doing that. You can look (and maybe even fix) my source code by clicking on the ROAD Programming link in my signature, going to the community seciton, and clicking downloads. It should be pretty obvious which one to choose (there is only one ). If you don''t feel like doing that, take a look at this code snippet that seems to be the problem. The app exits at the fscanf() line with no error message. It just quits like I hit Alt+F4 except the shutdown code isn''t called. I know this much because of the WriteError() statements. The one right before the fscanf() is written, but the one in the loop isn''t. I am very confused. My friends and the compiler agree that the syntax is correct. It SHOULD work, but it doesn''t. Please help! Here is the problem-code:
  bool CVectorModel::LoadModel(char *Filename) { FILE *File = fopen(Filename, "r"); int Color = 0; WriteError("Attempting to load model..."); if (!File) { WriteError("Unable to open Model"); return false; } Lines = 0; WriteError("Loading raw data..."); while (fscanf(File, "(%f, %f, %f)%f, %f, %f)=%d", Model[Lines].Start.x, Model[Lines].Start.y, Model[Lines].Start.z, Model[Lines].End.x, Model[Lines].End.y, Model[Lines].End.z, Color) && Lines < MAX_MODEL_LINES) { Model[Lines].Color = (unsigned short)Color; // set the color as unsigned short for 16bpp surface ++Lines; WriteError("Vector Line loaded..."); } WriteError("Model load successful"); return true; } 
I don''t know what''s wrong... It looks OK to me. Please pardon the widness of my post that the source will probably cause --------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

Visit the ROAD Programming Website for more programming help.

Share on other sites
Well, unless your variables "Model[Lines].Start.x, Model[Lines].Start.y", etc... are pointers, this will not work.
Scanf is trying to load into memory points held by those variables. So if the value of Model[Lines].Start.x is 0, for example, it's going to try and load at 0. This is Baaaaaaad!!!! Why don't you try this:

  while (fscanf(File, "(%f, %f, %f)(%f, %f, %f)=%d", &Model[Lines].Start.x, &Model[Lines].Start.y, &Model[Lines].Start.z, &Model[Lines].End.x, &Model[Lines].End.y, &Model[Lines].End.z, &Color) && Lines < MAX_MODEL_LINES)

That should work much better

That's just my opinion though...feel free to tear me to shreds ;-)

-=xelius=-

Edited by - Xelius on October 3, 2000 1:55:26 PM

Share on other sites
I know this won''t help you now, but you REALLY should allow your app to be run in fullscreen AND windowed mode. It really is very little extra code, and there are tutorials here on gamedev that shows how you can do this. In windowed mode you can step into the code and debug line by line. I always develop in windowed mode (with occasionally running in fullscreen to make sure that still works).

- Houdini

Share on other sites
I think that using the & in front of my parameters is what I need to do. The only compiler I have access to right now is DOS only, but I did a test and it worked (it didn''t work when I did it my way). Thanks.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

Visit the ROAD Programming Website for more programming help.

Share on other sites
No problem. I wanted to save you the frustration I had to go through when dealing with this. I remember (way back when...5/4 years ago to be exact and I''m 19 October 19th ) when I had just learned C/C++ and was having a terrible time with it. All my programs crashed! After reading a great book, I can''t remember, but it was one of those "Learn C the right way" books, I learned about the magic of pointers and that the reason all my programs were crashing was because my scanf''s never used the addresses to non-pointer types.
*poof* Problem solved

l8r dude

That's just my opinion though...feel free to tear me to shreds ;-)

-=xelius=-

• Partner Spotlight

• Forum Statistics

• Total Topics
627682
• Total Posts
2978623

• 9
• 14
• 12
• 10
• 12