# Game doesn't crash if currently printing

This topic is 1499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am a little confused as to why this happens in what I have been working on.

if( game_debug == true ) {
render_var( 16, 184, TEXT_LEFT, "FPS:", (int)framespersecond, true );
render_var( 16, 16, TEXT_LEFT, "CAMERA X:", (int)camera_x, true );
render_var( 16, 32, TEXT_LEFT, "CAMERA Y:", (int)camera_y, true );
if( lvl_name != NULL ) {
render_text( 320 - 16, 16, TEXT_RIGHT, "LEVEL: ", true );
render_text( 320 - 16, 32, TEXT_RIGHT, lvl_name, true );
}
} else {
render_text( 320 - 16, 16, TEXT_RIGHT, "F1: View Debug Info", true );
}


when I call upon change_level

int change_level( const char* filename ) {
/* clear any current level assets */
/* level information */
lvl_name = "";
...
/* camera coordinates */
camera_x = 0;
camera_y = 0;
/* tiles */
...
/* objects */
/* parse new level */
parse_level( filename );
/* tell user level has been changed */
printf( "level has been changed to: %s\n", lvl_name );
}


while game_debug is currently true, the game will crash. However, if I comment out the first three parts (rendering the framespersecond, camera_x, and camera_y) then the crash does not occur. The crash does not occur either if I put game_debug = false; somewhere within the change_level() function. Another weird thing (this is where the thread title comes in) is the game does not crash if I am currently printing something over and over again, so I could put printf("printing!\n"); above the line of code that renders framespersecond, and when I change levels (game_debug is not set to false in this instance), the crash does not occur.

Do you have any ideas as to why this anomaly happens? Thanks

##### Share on other sites

Don't know what you mean by crash-hunting, I listed some possible scenarios where crashing may/may not occur. If I don't have debug info toggle-able, and everything is just already out there, then the game doesn't crash either. I see if game_debug is true, the game crashes AFTER change_level is done. However say everything is commented out inside game_debug, then there is no crash at all. So it has to do something with rendering the text on screen, but nothing printed is erased when the level changes. So it's very confusing.

##### Share on other sites

You strongly imply that the three render_var lines appear to cause the "crash." In those lines, the only arguments that would seem to be a problem are framespersecond, camera_x and camera_y. As a wild guess, assuming those are float variables, have you tried converting them to int variables, and using the int variables as the render_var arguments?

I.e.,

int fps = (int)framespersecond;
render_var(..., fps,..);


EDIT: What does render_var do?

Edited by Buckeye

##### Share on other sites
int render_text( int x, int y, int allignment, char* text, int outline ) {
int i;
int text_length = strlen(text) * text_w;
int o_x, o_y;
for( i = 1; i < strlen(text) + 1; i++ ) {
double t_x = x + (text_w * i);
if( allignment == TEXT_LEFT )
t_x = x + (text_w * i) - text_w;
if( allignment == TEXT_CENTRE )
t_x = (x + (text_w * i)) - text_length/2 - text_w;
if( allignment == TEXT_RIGHT )
t_x = (x + (text_w * i)) - text_length - text_w;
if( outline == true )
for( o_x = -1; o_x <= 1; o_x++ )
for( o_y = -1; o_y <= 1; o_y++ )
draw_letter( t_x + o_x, y + o_y, text[i - 1], true );
draw_letter( t_x, y, text[i - 1], false );
}
free(text);
}
int render_var( int x, int y, int allignment, char *text, int var, int outline ) {
render_text( x, y, allignment, text, outline );
int var_spot = 0;
if( strlen(text) != 0 )
var_spot = (strlen(text))*text_w;
char var_text[20];
sprintf( var_text, "%d", var );
render_text( x + var_spot, y, allignment, var_text, outline );
}


##### Share on other sites

Couldn't add more text after I made that code bubble. They are converted to integers, as you can see, they render just fine. It's just weird that the game only crashes if game_debug is true and code for rendering text (is active) is inside the statement; if it's outside the game_debug statement, no crash; or if I am constantly printing anything inside the statement, no crash.

##### Share on other sites

I am just confused with this crashed, however I moved the function to another line (one line above it's comment) and now (for now) it works. I am baffled by this.

##### Share on other sites

Don't know what you mean by crash-hunting, I listed some possible scenarios where crashing may/may not occur. If I don't have debug info toggle-able, and everything is just already out there, then the game doesn't crash either. I see if game_debug is true, the game crashes AFTER change_level is done. However say everything is commented out inside game_debug, then there is no crash at all. So it has to do something with rendering the text on screen, but nothing printed is erased when the level changes. So it's very confusing.

It *might* have something to do with that. It might not. That is what debuggers were invented for.

I asked what you had done for crash hunting for the additional information linked to by ApochPiQ. For example, when the crash occurs in the debugger, where does the crash occur? Does it appear inside a function you know, inside a system function, or in some seemingly random memory location? What does your call stack look like? What was your previous instruction?

Crashes typically include some sort of message indicating the error, or provide a minidump or other useful data. If an error message what exactly does it say? If a minidump what happens when you load it up with your debug info? Those random numbers mean things, and the guide linked to above can help you understand them. (Or we could retype the information hundreds of times, doing it yet again for your post. Please just go read the other links.)

Other than uncommenting some lines and moving a bit of code around to hide the bug, what have you actually done (you know, like a computer scientist rather than code monkey) to experiment on the issue, identify it, and correct it?

##### Share on other sites

I am not sure if there is a bug, I just changed the order of some things and it worked. Maybe it was an order issue. Console did not give any error messages, even when I had a friend look at it and supply me a document of the console of what he ran.

1. 1
2. 2
JoeJ
20
3. 3
frob
19
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632204
• Total Posts
3004764

×