From d18cd3802caf19ce7f1675068b5bb3661932bc5a Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Wed, 15 Jul 2026 07:54:11 -0400 Subject: [PATCH] cleanup parts of code... start trying to figure out weird bug --- game.h | 4 ++++ level.c | 32 ++++++++++++++++++++++++++------ main_v2.c | 9 +++++++++ physics.c | 3 +-- player.c | 11 +++++++++-- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/game.h b/game.h index a871118..0a9af97 100644 --- a/game.h +++ b/game.h @@ -18,6 +18,7 @@ #define LEVELS 3 struct character *spielersetup(void); +int next_level(void); int bühnezeichnen(void); //i dont think stage works here but it seems better than window int spielerzeichnen(void); @@ -29,6 +30,9 @@ int physics(float delta, struct character *player); int on_floor(struct Rectangle *rect); int in_floor(struct Rectangle *rect); +int level_cleanup(void); +int player_cleanup(void); + //structures struct character { struct Rectangle rect; diff --git a/level.c b/level.c index 3267378..b55a211 100644 --- a/level.c +++ b/level.c @@ -30,6 +30,7 @@ int bühnezeichnen(void) }; if (frozen) { //currently in dialogue + printf("d"); drawdialogue(); if (IsKeyPressed(ADVANCEKEY)) { if (++current_dialogue == stages[level].dialogue_count) { //dialogue over @@ -75,12 +76,22 @@ int on_floor(struct Rectangle *rect) //on floor == no overlap but right next to int drawdialogue(void) { - struct dialogue *dlg = &(stages[level].dialogues[current_dialogue]); + struct dialogue dlg = stages[level].dialogues[current_dialogue]; + printf("g"); //grab dialogue DrawRectangle(0,DLGY,640,DLGHEIGHT,RAYWHITE); - drawcharname(dlg->charaname,dlg->characolour); - drawcharimage(dlg->image); - drawdialogueline(dlg->line); - + printf("r"); //rectange + //drawcharname(dlg.charaname,dlg.characolour); + DrawText(dlg.charaname,DLGPADDING,DLGY + DLGPADDING,CHARANAMETEXTSIZE,dlg.characolour); + printf("n"); //name THIS IS WHERE IT CRASHES + drawcharimage(dlg.image); + printf("i"); //image THIS CRASHES TOO?? ig... the issue is with dlg->???? but specifically when the function uses it... AND SPECIFICALLY WHEN IT'S A STRING + // so... our mystery bug has these traits: + //only happens on the second level played (NOT only on level == 1. If you manually set level to 1 at the start it crashes on entering stages[2] instead. + //happens when a property of dlg is accessed in one of functions and used to do smth (so it doesn't crash if it's just entered into the function) (although maybe that's bc of compiler??) + //it also happens if DrawText (and presumably the other ones too) are attempted inside of drawdialogue(). + //the property must be a string. + drawdialogueline(dlg.line); + printf("l"); //line return 1; }; @@ -90,14 +101,17 @@ int drawcharname(char *name, Color colour) return 1; } +static Texture2D txtr; + int drawcharimage(char *filename) { static char *lastfilename = ""; - static Texture2D txtr; if (lastfilename != filename) { + UnloadTexture(txtr); Image img = LoadImage(filename); ImageResize(&img, CHARADISPLAYWIDTH - DLGPADDING * 2, CHARADISPLAYWIDTH - DLGPADDING * 2); txtr = LoadTextureFromImage(img); + UnloadImage(img); lastfilename = filename; } DrawTexture(txtr,DLGPADDING,DLGY + CHARANAMETEXTSIZE + DLGPADDING * 3,WHITE); @@ -108,3 +122,9 @@ int drawdialogueline(char *line) { DrawText(line, CHARADISPLAYWIDTH + DLGPADDING, DLGY + DLGPADDING * 2 ,20, BLACK); //add text wrapping later }; + +int cleanup_level(void) +{ + UnloadTexture(txtr); + return 1; +} diff --git a/main_v2.c b/main_v2.c index 0ae2e90..9fd1479 100644 --- a/main_v2.c +++ b/main_v2.c @@ -43,3 +43,12 @@ int variables(float delta, struct character *player) physics(delta, player); return 1; // :p } + +int next_level(void) +{ + level += 1; + //printf("incremented level"); + frozen = 1; + printf("set frozen\n"); + return 1; +} diff --git a/physics.c b/physics.c index 6d50d7e..4b61882 100644 --- a/physics.c +++ b/physics.c @@ -11,9 +11,8 @@ int physics(float delta, struct character *player) gravity(delta, player); move_player(delta,player); if (player->rect.x > SCREENWIDTH) { - level++; player->rect.x = 15; player->rect.y = 120; - frozen=1; + next_level(); }; return 1; } diff --git a/player.c b/player.c index d063abb..c3c1845 100644 --- a/player.c +++ b/player.c @@ -10,7 +10,9 @@ static float delta_player; struct character *spielersetup(void) { - front_single = LoadTextureFromImage(LoadImage("aichan-front.png")); + Image img = LoadImage("aichan-front.png"); + front_single = LoadTextureFromImage(img); + UnloadImage(img); front_sheet = LoadImage("aichan-front-sheet.png"); @@ -59,4 +61,9 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic return 1; } - +int player_cleanup(void) +{ + UnloadTexture(front_single); + UnloadImage(front_sheet); + return 1; +} -- 2.47.3