[Fix] More warnings.

This commit is contained in:
Allanis 2013-07-24 16:10:13 +01:00
parent 1d734e7898
commit d6643b0a51
3 changed files with 34 additions and 4 deletions

View File

@ -48,6 +48,7 @@ int menu_open = 0;
void menu_main_close(void);
static void menu_main_load(char* str);
static void menu_main_new(char* str);
static void menu_main_exit(char* str);
/* Small menu. */
static void menu_small_close(char* str);
static void edit_options(char* str);
@ -100,7 +101,7 @@ void menu_main(void) {
BUTTON_WIDTH, BUTTON_HEIGHT,
"btnOptions", "Options", (void(*)(char*)) edit_options);
window_addButton(wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
"btnExit", "Exit", (void(*)(char*)) exit_game);
"btnExit", "Exit", menu_main_exit);
menu_Open(MENU_MAIN);
}
@ -108,7 +109,7 @@ void menu_main(void) {
void menu_main_close(void) {
window_destroy(window_get("Main Menu"));
gl_freeTexture(window_getImage(window_get("BG"), "imgBG"));
gl_freeTexture(window_getImage(window_get("BG"), "imgLogo"));
window_destroy(window_get("BG"));
menu_Close(MENU_MAIN);
@ -127,6 +128,25 @@ static void menu_main_new(char* str) {
player_new();
}
static void menu_main_exit(char* str) {
(void)str;
unsigned int wid;
wid = window_get("BG");
/*
* Ugly hack to prevent player.c from segfaulting due to the fact
* that game will attempt to render while waiting for the quit event
* pushed by exit_game() to be handled without actually having a player
* nor anything of the likes (nor toolkit to stop rendering) while not
* leaking any texture.
*/
gl_freeTexture(window_getImage(wid, "imgLogo"));
window_modifyImage(wid, "imgLogo", NULL);
exit_game();
}
/* Ze ingame menu. */
/* Small ingame menu. */
void menu_small(void) {

View File

@ -453,6 +453,11 @@ glTexture* gl_newSprite(const char* path, const int sx, const int sy) {
void gl_freeTexture(glTexture* texture) {
glTexList* cur, *last;
if(texture == NULL) {
WARN("Attempting to free NULL texture!");
return;
}
/* See if we can find it in stack. */
last = NULL;
for(cur = texture_list; cur != NULL; cur = cur->next) {
@ -466,7 +471,10 @@ void gl_freeTexture(glTexture* texture) {
free(texture);
/* Free the list node. */
if(last == NULL) /* Incase it's the last texture. */
if(last == NULL) /* Case there's no texture before it. */
if(cur->next != NULL)
texture_list = cur->next;
else /* Case it's the last texture. */
texture_list = NULL;
else
last->next = cur->next;

View File

@ -377,6 +377,8 @@ static Widget* window_getwgt(const unsigned int wid, char* name) {
for(i = 0; i < wdw->nwidgets; i++)
if(strcmp(wdw->widgets[i].name, name)==0)
return &wdw->widgets[i];
WARN("Widget '%s' not found in window '%u'!", name, wid);
return NULL;
}