diff --git a/src/battle/battle.c b/src/battle/battle.c index 0769312..040d330 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -60,8 +60,6 @@ void initBattle(void) initStars(); - initBullets(); - initBackground(); initEffects(); diff --git a/src/battle/items.c b/src/battle/items.c index a2acb0b..1d9931e 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -54,6 +54,7 @@ void loadItemDefs(void) SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); defTail->next = e; + defTail = e; } cJSON_Delete(root); diff --git a/src/battle/quadtree.c b/src/battle/quadtree.c index 303c96a..c6eecf6 100644 --- a/src/battle/quadtree.c +++ b/src/battle/quadtree.c @@ -24,8 +24,6 @@ static Entity **candidates; static int cIndex; static int cCapacity; -static int memory; - static int getIndex(Quadtree *root, int x, int y, int w, int h); static void removeEntity(Entity *e, Quadtree *root); static int candidatesComparator(const void *a, const void *b); @@ -48,11 +46,12 @@ void initQuadtree(Quadtree *root) root->ents = malloc(sizeof(Entity*) * root->capacity); memset(root->ents, 0, sizeof(Entity*) * root->capacity); - memory = 0; + cIndex = 0; + cCapacity = QT_INITIAL_CAPACITY; + candidates = malloc(sizeof(Entity*) * cCapacity); + memset(candidates, 0, sizeof(Entity*) * cCapacity); } - memory += sizeof(Quadtree); - w = root->w / 2; h = root->h / 2; @@ -101,11 +100,6 @@ void initQuadtree(Quadtree *root) initQuadtree(node); } } - - cIndex = 0; - cCapacity = QT_INITIAL_CAPACITY; - candidates = malloc(sizeof(Entity*) * cCapacity); - memset(candidates, 0, sizeof(Entity*) * cCapacity); } void addToQuadtree(Entity *e, Quadtree *root) @@ -277,23 +271,28 @@ void destroyQuadtree(void) { destroyQuadtreeNode(&battle.quadtree); - free(candidates); - - candidates = NULL; + if (candidates) + { + free(candidates); + + candidates = NULL; + } } static void destroyQuadtreeNode(Quadtree *root) { int i; + free(root->ents); + + root->ents = NULL; + if (root->node[0]) { for (i = 0 ; i < 4 ; i++) { destroyQuadtreeNode(root->node[i]); - free(root->node[i]->ents); - free(root->node[i]); root->node[i] = NULL; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 9ada9e3..b4789ee 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -197,6 +197,8 @@ void loadMission(char *filename) battle.planetHeight *= planetScale; srand(time(NULL)); + + cJSON_Delete(root); free(text); diff --git a/src/system/init.c b/src/system/init.c index 507c0b8..e9651c6 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -131,9 +131,9 @@ void initGameSystem(void) initStarSystems, initChallenges, initStats, - initBattle, initModalDialog, initBackground, + initStars, initControls }; diff --git a/src/system/init.h b/src/system/init.h index 78133cb..6d6dd05 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -70,6 +70,7 @@ extern void createSaveFolder(void); extern void setLanguage(char *applicationName, char *languageCode); extern char *getLookupName(char *prefix, long num); extern long lookup(char *name); +extern void initStars(void); extern App app; extern Colors colors; diff --git a/src/system/resources.c b/src/system/resources.c index d4b5ef1..ba88d56 100644 --- a/src/system/resources.c +++ b/src/system/resources.c @@ -98,7 +98,20 @@ char *getMusicFilename(int i) void destroyResources(void) { - free(backgrounds); - free(planets); - free(musicFiles); + int i; + + for (i = 0 ; i < numBackgrounds ; i++) + { + free(backgrounds[i]); + } + + for (i = 0 ; i < numPlanets ; i++) + { + free(planets[i]); + } + + for (i = 0 ; i < numMusicFiles ; i++) + { + free(musicFiles[i]); + } } diff --git a/src/system/widgets.c b/src/system/widgets.c index c5fa49a..67690b0 100644 --- a/src/system/widgets.c +++ b/src/system/widgets.c @@ -507,6 +507,8 @@ void destroyWidgets(void) { free(w->options[i]); } + + free(w->options); next = w->next; free(w);