From 811d11af089a50110d2c2a583d6065448044fe71 Mon Sep 17 00:00:00 2001 From: Piotr Kozak Date: Sat, 7 Mar 2026 12:59:35 +0100 Subject: [PATCH] Save file bugfix and high dpi support --- main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index d133fcf..fac03f0 100644 --- a/main.c +++ b/main.c @@ -30,14 +30,17 @@ static GameState_t game_state; int main() { srand(time(NULL)); - reset_board(&game_state); - FILE* game_file = fopen("save.dat", "rb"); + FILE *game_file = fopen("save.dat", "rb"); if (game_file != NULL) { - fseek(game_file, 0, SEEK_SET); - fread(&game_state, sizeof(GameState_t), 1, game_file); + if (fread(&game_state, sizeof(GameState_t), 1, game_file) != 1) { + reset_board(&game_state); + } fclose(game_file); + } else { + reset_board(&game_state); } + SetConfigFlags(FLAG_WINDOW_HIGHDPI); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "2048"); SetTargetFPS(30); // So my laptop doesn't burn @@ -52,7 +55,7 @@ int main() { int pos_y = BOARD_MARGIN + y * (TILE_SIZE + TILE_SPACING); int color_index = (tile_value == 0) ? 0 : (int)log2(tile_value); - if (color_index >= sizeof(tile_colors) / sizeof(tile_colors[0])) { + if ((size_t)color_index >= sizeof(tile_colors) / sizeof(tile_colors[0])) { color_index = sizeof(tile_colors) / sizeof(tile_colors[0]) - 1; // Cap to the last color }