Fixed segfault that happend when you'd exit the ingame-state.
This commit is contained in:
11
src/main.c
11
src/main.c
@@ -1,5 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "presentation/states/state_ingame.h"
|
||||
#include "presentation/states/state_main_menu.h"
|
||||
@@ -29,18 +30,16 @@ int main() {
|
||||
break;
|
||||
}
|
||||
|
||||
Presentation_State *state = presentation_state_machine.current;
|
||||
|
||||
// Tick.
|
||||
if(state != NULL && state->tick != NULL) {
|
||||
state->tick(state);
|
||||
if(presentation_state_machine.current != NULL && presentation_state_machine.current->tick != NULL) {
|
||||
presentation_state_machine.current->tick(presentation_state_machine.current);
|
||||
}
|
||||
|
||||
// Render.
|
||||
BeginDrawing();
|
||||
{
|
||||
if(state != NULL && state->render != NULL) {
|
||||
state->render(state);
|
||||
if(presentation_state_machine.current != NULL && presentation_state_machine.current->render != NULL) {
|
||||
presentation_state_machine.current->render(presentation_state_machine.current);
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
|
||||
@@ -91,7 +91,10 @@ static void state_render(Presentation_State *state) {
|
||||
ClearBackground((Color) { 240, 236, 226, 255 });
|
||||
|
||||
Simulation_World *sim_world = &g_current_session->simulation_world;
|
||||
assert(sim_world != NULL);
|
||||
|
||||
Game_World *world = sim_world->game_world;
|
||||
assert(world != NULL);
|
||||
Grid *grid = &world->grid;
|
||||
|
||||
uint32_t grid_total_size = grid->width * grid->height;
|
||||
|
||||
@@ -10,7 +10,7 @@ static void state_enter(Presentation_State *state) {
|
||||
Presentation_State_Main_Menu_Context *ctx = (Presentation_State_Main_Menu_Context *)state->context;
|
||||
(void)ctx;
|
||||
|
||||
printf("Entered main menu\n");
|
||||
ctx->mode = Main_Menu_Mode_Home;
|
||||
}
|
||||
|
||||
static void state_tick(Presentation_State *state) {
|
||||
|
||||
@@ -87,10 +87,10 @@ void game_session_init_default_settings(bool is_singleplayer, Game_Session_Setti
|
||||
static void game_session_tick(Game_Session *session) {
|
||||
// Update input.
|
||||
for(uint16_t i = 0; i < session->settings.max_players; i++) {
|
||||
Game_Session_Player *session_player = &session->players[i];
|
||||
Game_Session_Player *session_player = &session->players[i];
|
||||
|
||||
{ // Check if any players have joined/disconnected by comparing against the previous session_player.
|
||||
Game_Session_Player *session_player_prev = &session->players_prev[i];
|
||||
Game_Session_Player *session_player_prev = &session->players_prev[i];
|
||||
|
||||
bool was_active = session_player_prev->active;
|
||||
bool is_active = session_player->active;
|
||||
|
||||
Reference in New Issue
Block a user