commit a288c4b3a2ad849b34b65dd6a5ce16fce599cfc8
parent 79bca4490b43e230628e82d786431bb5013fce67
Author: William Casarin <jb55@jb55.com>
Date: Mon, 27 Apr 2020 20:29:46 -0700
initialize gpu programs
otherwise we get memory corruption
Diffstat:
5 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -90,6 +90,7 @@ void init_misc(struct game *game, int width, int height) {
struct node *root = new_node(&res->root_id);
struct node *sun_camera = new_node(&res->sun_camera_id);
+
struct terrain *terrain = &game->terrain;
struct entity *player;
@@ -226,7 +227,13 @@ void init_controller(struct input *input) {
}
}
+void init_resources(struct resources *res)
+{
+ memset(res, 0, sizeof(*res));
+}
+
void game_init(struct game *game, int width, int height) {
+ init_resources(&game->test_resources);
init_sdl(&game->window, width, height);
init_gl(&game->test_resources, width, height);
init_entity_system();
diff --git a/src/input.c b/src/input.c
@@ -140,6 +140,7 @@ void init_input(struct input *input) {
memset(input->key_edge_states, 0, sizeof(input->key_edge_states));
memset(input->button_edge_states, 0, sizeof(input->button_edge_states));
memset(input->axis, 0, sizeof(input->axis));
+ memset(input->mbuttons, 0, sizeof(input->mbuttons));
input->axis_min_input = 1024;
input->mx = 0;
input->my = 0;
diff --git a/src/shader.c b/src/shader.c
@@ -145,6 +145,11 @@ int make_shader(GLenum type, const char *filename, struct shader *shader) {
#define N_SHADERS 3
+void init_gpu_program(struct gpu_program *program) {
+ program->n_shaders = 0;
+ memset(program->shaders, 0, sizeof(program->shaders));
+}
+
#ifdef DEBUG
int reload_program(struct gpu_program *program) {
int ok;
@@ -154,6 +159,8 @@ int reload_program(struct gpu_program *program) {
struct shader new_shaders[n_shaders];
struct shader *new_shaders_p[n_shaders];
+ init_gpu_program(&new_program);
+
int changes[n_shaders];
for (int i = 0; i < n_shaders; i++) {
diff --git a/src/shader.h b/src/shader.h
@@ -32,6 +32,7 @@ struct gpu_program {
int reload_program(struct gpu_program *program);
int make_shader(GLenum type, const char *filename, struct shader *shader);
+void init_gpu_program(struct gpu_program *program);
int make_program_from_shaders(struct shader **shaders,
int n_shaders,
struct gpu_program *program);
diff --git a/test/test_resource.c b/test/test_resource.c
@@ -74,8 +74,7 @@ static void test_compact()
static void test_int_resource_manager()
{
printf("test_int_resource_manager\n");
- struct resource_manager r
-;
+ struct resource_manager r;
struct resource_id id, first_id;
int *p;
// 2 item case