• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
NicholasLopez

Game doesn't crash if currently printing

17 posts in this topic

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

0

Share this post


Link to post
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.

0

Share this post


Link to post
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 );
} 
0

Share this post


Link to post
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.

0

Share this post


Link to post
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.

0

Share this post


Link to post
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?
1

Share this post


Link to post
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.

0

Share this post


Link to post
Share on other sites
Do include stdio.h?

The printf-functions have a variable parameter list. Often make problems if no prototype available.
0

Share this post


Link to post
Share on other sites

As mentioned by LennyLen you're freeing memory in render_text (the line: free(text);) that was never allocated with malloc or new.  When you call a function with a literal string (example: function("hello")), it does not need to be freed.  Also the function render_var calls render_text which frees the text string and then render_var tries to operate on that text afterwards with strlen(text). These things can lead to a crash.

1

Share this post


Link to post
Share on other sites
Well, it's a bit more complicated than that:

void thing(const char* text) { 
    // Do stuff with text

    free(text);
}

int main() {
    const char* a = "abc";
    const char b[] = "def"
    char* c = malloc(4);
    char* d = new char[4];

    sprintf(c,"ghi");
    sprintf(d,"jkl");
   
    thing("mno"); // No!
    thing(a);     // No!
    thing(b);     // No!
    thing(c);     // Okay
    thing(d);     // No!

    // free(c);
    // delete[] d;
}
Here, [tt]thing[/tt] is assuming ownership of [tt]text[/tt] which isn't always the desired behavior, as shown in the sample program here.
1

Share this post


Link to post
Share on other sites

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  
Followers 0