Fixed crash on exit

dev
shariq 8 years ago
parent 18304569f6
commit da302520b7
  1. 3
      orgfile.org
  2. 7
      src/entity.c
  3. 2
      src/file_io.c
  4. 2
      src/framebuffer.c
  5. 7
      src/game.c
  6. 6
      src/game.h
  7. 12
      src/geometry.c
  8. 3
      src/input.c
  9. 1
      src/light.c
  10. 6
      src/model.c
  11. 1
      src/model.h
  12. 6
      src/platform.c
  13. 1
      src/platform.h
  14. 2
      src/shader.c
  15. 4
      src/sound.c
  16. 2
      src/texture.c

@ -263,7 +263,8 @@ x Log output on every run.
- State "DONE" from "TODO" [2017-05-24 Wed 17:12] - State "DONE" from "TODO" [2017-05-24 Wed 17:12]
** TODO Add default keybindings ** TODO Add default keybindings
** TODO Write default config/keybindings etc to file if none are found in preferences dir ** TODO Write default config/keybindings etc to file if none are found in preferences dir
** TODO Fix input map bugs ** DONE Fix input map bugs
- State "DONE" from "TODO" [2017-05-31 Wed 23:19]
** TODO Wrap malloc and free calls in custom functions to track usage ** TODO Wrap malloc and free calls in custom functions to track usage
** TODO Flatpak packaging for linux releases ** TODO Flatpak packaging for linux releases
** TODO Use hashmap for debugvar slots in editor ** TODO Use hashmap for debugvar slots in editor

@ -24,8 +24,11 @@ void entity_init(void)
void entity_cleanup(void) void entity_cleanup(void)
{ {
for(int i = 0; i < array_len(entity_list); i++) if(array_len(empty_indices) < array_len(entity_list))
entity_remove(i); {
for(int i = 0; i < array_len(entity_list); i++)
entity_remove(i);
}
array_free(entity_list); array_free(entity_list);
array_free(empty_indices); array_free(empty_indices);

@ -18,6 +18,8 @@ void io_file_cleanup(void)
{ {
if(install_directory) free(install_directory); if(install_directory) free(install_directory);
if(user_directory) free(user_directory); if(user_directory) free(user_directory);
install_directory = NULL;
user_directory = NULL;
} }
char* io_file_read(const int directory_type, const char* path, const char* mode, long* file_size) char* io_file_read(const int directory_type, const char* path, const char* mode, long* file_size)

@ -34,6 +34,8 @@ void framebuffer_cleanup(void)
array_free(fbo_list); array_free(fbo_list);
array_free(empty_indices); array_free(empty_indices);
fbo_list = NULL;
empty_indices = NULL;
} }
int framebuffer_create(int width, int height, int has_depth, int has_color, int resizeable) int framebuffer_create(int width, int height, int has_depth, int has_color, int resizeable)

@ -60,7 +60,7 @@ int game_init(struct Window* window)
game_state->window = window; game_state->window = window;
game_state->player_node = -1; game_state->player_node = -1;
game_state->player_pitch_node = -1; game_state->player_pitch_node = -1;
game_state->is_initialized = 0; game_state->is_initialized = false;
} }
/* TODO: Decouple systems' init/cleanup from game, they should exist and run even if there's no "game" */ /* TODO: Decouple systems' init/cleanup from game, they should exist and run even if there's no "game" */
@ -81,7 +81,7 @@ int game_init(struct Window* window)
/* Debug scene setup */ /* Debug scene setup */
scene_setup(); scene_setup();
game_state->is_initialized = 1; game_state->is_initialized = true;
return run(); return run();
} }
@ -1558,7 +1558,6 @@ void game_cleanup(void)
editor_cleanup(); editor_cleanup();
scene_cleanup(); scene_cleanup();
entity_cleanup(); entity_cleanup();
model_cleanup();
material_cleanup(); material_cleanup();
geom_cleanup(); geom_cleanup();
light_cleanup(); light_cleanup();
@ -1571,9 +1570,9 @@ void game_cleanup(void)
sound_cleanup(); sound_cleanup();
window_destroy(game_state->window); window_destroy(game_state->window);
gl_cleanup(); gl_cleanup();
window_cleanup();
} }
free(game_state); free(game_state);
game_state = NULL;
} }
} }

@ -1,5 +1,5 @@
#ifndef game_H #ifndef GAME_H
#define game_H #define GAME_H
#include "platform.h" #include "platform.h"
@ -8,7 +8,7 @@ struct Game_State
struct Window* window; struct Window* window;
int player_node; int player_node;
int player_pitch_node; int player_pitch_node;
int is_initialized; bool is_initialized;
}; };

@ -381,12 +381,12 @@ int geom_render_in_frustum(int index,
{ {
geom_render(index, draw_mode); geom_render(index, draw_mode);
rendered = array_len(geometry->indices); rendered = array_len(geometry->indices);
/* intersection = bv_intersect_frustum_box(frustum, &geometry->bounding_box, transform); */ intersection = bv_intersect_frustum_box(frustum, &geometry->bounding_box, transform);
/* if(intersection == IT_INTERSECT || intersection == IT_INSIDE) */ if(intersection == IT_INTERSECT || intersection == IT_INSIDE)
/* { */ {
/* geom_render(index, draw_mode); */ geom_render(index, draw_mode);
/* rendered = array_len(geometry->indices); */ rendered = array_len(geometry->indices);
/* } */ }
} }
return rendered; return rendered;
} }

@ -80,15 +80,14 @@ void input_init(void)
void input_cleanup(void) void input_cleanup(void)
{ {
//input_keybinds_save("keybindings.cfg");
for(int i = 0; i < array_len(input_map_list); i++) for(int i = 0; i < array_len(input_map_list); i++)
{ {
struct Input_Map* map = &input_map_list[i]; struct Input_Map* map = &input_map_list[i];
//log_message("Map : %s, Num keys : %d", map->name, array_len(map->keys));
if(map->name) free(map->name); if(map->name) free(map->name);
array_free(map->keys); array_free(map->keys);
} }
array_free(input_map_list); array_free(input_map_list);
input_map_list = NULL;
} }
bool input_keybinds_load(const char* filename, int directory_type) bool input_keybinds_load(const char* filename, int directory_type)

@ -14,6 +14,7 @@ void light_init(void)
void light_cleanup(void) void light_cleanup(void)
{ {
array_free(light_list); array_free(light_list);
light_list = NULL;
} }

@ -57,12 +57,10 @@ void model_destroy(struct Entity* entity)
free(model->material_params[i].value); free(model->material_params[i].value);
array_free(model->material_params); array_free(model->material_params);
model->material_params = NULL;
model->material = -1;
} }
void model_cleanup(void)
{
}
void model_render_all(struct Entity* camera_entity, int draw_mode) void model_render_all(struct Entity* camera_entity, int draw_mode)
{ {

@ -9,7 +9,6 @@ struct Entity;
void model_init(void); void model_init(void);
void model_create(struct Entity* entity, const char* geo_name, const char* material_name); void model_create(struct Entity* entity, const char* geo_name, const char* material_name);
void model_destroy(struct Entity* entity); void model_destroy(struct Entity* entity);
void model_cleanup(void);
void model_render_all(struct Entity* camera_entity, int draw_mode); void model_render_all(struct Entity* camera_entity, int draw_mode);
int model_set_material_param(struct Entity* entity, const char* name, void* value); int model_set_material_param(struct Entity* entity, const char* name, void* value);
int model_get_material_param(struct Entity* entity, const char* name, void* value_out); int model_get_material_param(struct Entity* entity, const char* name, void* value_out);

@ -149,11 +149,6 @@ void window_destroy(struct Window* window)
SDL_DestroyWindow((SDL_Window*)window->sdl_window); SDL_DestroyWindow((SDL_Window*)window->sdl_window);
} }
void window_cleanup(void)
{
}
void window_set_size(struct Window* window, int width, int height) void window_set_size(struct Window* window, int width, int height)
{ {
SDL_SetWindowSize((SDL_Window*)window->sdl_window, width, height); SDL_SetWindowSize((SDL_Window*)window->sdl_window, width, height);
@ -208,6 +203,7 @@ int platform_init(void)
void platform_cleanup(void) void platform_cleanup(void)
{ {
if(platform_state) free(platform_state); if(platform_state) free(platform_state);
platform_state = NULL;
SDL_Quit(); SDL_Quit();
} }

@ -20,7 +20,6 @@ void window_show(struct Window* window);
void window_hide(struct Window* window); void window_hide(struct Window* window);
void window_raise(struct Window* window); void window_raise(struct Window* window);
void window_make_context_current(struct Window* window); void window_make_context_current(struct Window* window);
void window_cleanup(void);
void window_set_size(struct Window* window, int width, int height); void window_set_size(struct Window* window, int width, int height);
void window_get_size(struct Window* window, int* out_width, int* out_height); void window_get_size(struct Window* window, int* out_width, int* out_height);
void window_get_drawable_size(struct Window* window, int* out_width, int* out_height); void window_get_drawable_size(struct Window* window, int* out_width, int* out_height);

@ -299,6 +299,8 @@ void shader_cleanup(void)
array_free(shader_list); array_free(shader_list);
array_free(empty_indices); array_free(empty_indices);
shader_list = NULL;
empty_indices = NULL;
} }
void shader_set_uniform(const int uniform_type, const int uniform_loc, void* value) void shader_set_uniform(const int uniform_type, const int uniform_loc, void* value)

@ -135,6 +135,10 @@ void sound_cleanup(void)
alcMakeContextCurrent(NULL); alcMakeContextCurrent(NULL);
alcDestroyContext(sound_state.context); alcDestroyContext(sound_state.context);
alcCloseDevice(sound_state.device); alcCloseDevice(sound_state.device);
sound_state.context = NULL;
sound_state.device = NULL;
sound_state.volume = 0.f;
sound_state.listener_entity = -1;
} }
void sound_error_check(const char* file, unsigned int line, const char* expression) void sound_error_check(const char* file, unsigned int line, const char* expression)

@ -152,6 +152,8 @@ void texture_cleanup(void)
array_free(texture_list); array_free(texture_list);
array_free(empty_indices); array_free(empty_indices);
texture_list = NULL;
empty_indices = NULL;
} }
void texture_bind(int index) void texture_bind(int index)

Loading…
Cancel
Save