Advertisement

Alot of stuff not working..

Started by July 09, 2000 10:44 PM
2 comments, last by Chazz 24 years, 6 months ago
Hey.. I am writing a game engine that reads Quake .map files and shows them in OpenGL.. THe code compiles fine but the program crashes when it runs.. I have a loadmap function that loads a Worldcraft created map.map file using this function: // while(!strcmpi((const char *) end, "}")) // { c = 0; while(c < 6) { c++; fgets(oneline, 255, infile); // sscanf(oneline, "%s %f %f %f ", dummy, x, y, z ); if(c == 1) { // temp->point1->x = x; // temp->point1->y = y; // temp->point1->z = z; } if(c == 6) { // temp->point2->x = x; // temp->point2->y = y; // temp->point2->z = z; } } fgets(oneline, 255, infile); fgets(oneline, 255, infile); // sscanf(oneline, "%s", end); // makebrush(temp); // } Everything that is commented out crashes the program when it runs (it compiles without a hitch though).. Does anyone have any help?? I could really use it.. My engine uses linked lists to store each ''brush'' (rectangular prism) in memory. The brush consists of a upper-furthest-left point and the lower-nearest-right point. I calculate the 6 polygons that make it up using those two points.. My loading loop crashes it.. Does anyone know why????
-Chazz
There are a lot of possible problems here, but we''ll need to see more code.

// while(!strcmpi((const char *) end, "}"))

A common reason for strcmp() to fail is when one of the strings is NULL, so I''m guessing end=NULL (or a bad pointer) here.

// fgets(oneline, 255, infile);

What is oneline? It should be char oneline[255];

// sscanf(oneline, "%s %f %f %f ", dummy, x, y, z );

If oneline is bad, this will crash. What is dummy? It should also be a buffer large enough to hold your string. And since you are scanning floating values that will get loaded into particular addresses, you''ll need to do &x, &y, &z. That''s a common mistake with the scanf functions.


// temp->point1->x = x;
// temp->point1->y = y;
// temp->point1->z = z;

Is temp a valid pointer? Does it point to some fixed structure or have you malloc''d it? If not, this is a likely crash.

HTH
Advertisement
Wow, I read this post then left then came back. An anonymous poster used the purpose of an anonymous post properly!! That''s great! Congratulations and thank-you for using anonymous posts properly!

Well, I don''t know anything about C or C++ or Quake .map files so I''ll just leave now... :-)

See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
That helped ALOT anonymous.. Thanks alot, that really helped....

yes, end = NULL and all the other things are true too, thanks alot.. You are a god..
-Chazz

This topic is closed to new replies.

Advertisement