From 42310b31f51a176a6f11ea403a74a6b014b82ab2 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 28 Apr 2004 13:18:54 +0000 Subject: [PATCH] fixes some remaining memory leaks SVN-Revision: 803 --- src/resources.cpp | 3 +++ src/setup.cpp | 2 +- src/setup.h | 1 + src/supertux.cpp | 1 + src/text.cpp | 14 ++++++-------- src/texture.cpp | 12 ++++++++++++ src/title.cpp | 1 + src/world.cpp | 4 ++++ src/world.h | 3 ++- src/worldmap.cpp | 7 +++++-- 10 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/resources.cpp b/src/resources.cpp index 024694bb2..64a60cf8a 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -218,6 +218,7 @@ void unloadshared(void) for (i = 0; i < 2; i++) delete img_flag[i]; + delete img_red_glow; for (i = 0; i < 4; i++) { delete img_distro[i]; @@ -225,6 +226,8 @@ void unloadshared(void) delete img_cloud[1][i]; } + delete tux_life; + for (i = 0; i < NUM_SOUNDS; i++) free_chunk(sounds[i]); diff --git a/src/setup.cpp b/src/setup.cpp index 449b8e32a..d28669126 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -600,7 +600,6 @@ void st_general_free(void) { /* Free global images: */ - delete black_text; delete gold_text; delete white_text; @@ -608,6 +607,7 @@ void st_general_free(void) delete red_text; delete white_small_text; delete white_big_text; + delete yellow_nums; /* Free GUI/menu images: */ delete checkbox; diff --git a/src/setup.h b/src/setup.h index 331a7656a..1661be7bc 100644 --- a/src/setup.h +++ b/src/setup.h @@ -33,6 +33,7 @@ string_list_type dfiles(const char *rel_path, const char* glob, const char* exce void free_strings(char **strings, int num); void st_directory_setup(void); void st_general_setup(void); +void st_general_free(); void st_video_setup_sdl(void); void st_video_setup_gl(void); void st_video_setup(void); diff --git a/src/supertux.cpp b/src/supertux.cpp index ce71bc992..facb42a3e 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -65,6 +65,7 @@ int main(int argc, char * argv[]) updatescreen(); unloadshared(); + st_general_free(); TileManager::destroy_instance(); #ifdef DEBUG Surface::debug_check(); diff --git a/src/text.cpp b/src/text.cpp index 6d2e3a5d4..ee0e7b882 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -70,6 +70,12 @@ Text::Text(const std::string& file, int kind_, int w_, int h_) SDL_FreeSurface(conv); } +Text::~Text() +{ + delete chars; + delete shadow_chars; +} + void Text::draw(const char* text, int x, int y, int shadowsize, int update) { @@ -182,14 +188,6 @@ Text::drawf(const char* text, int x, int y, } } -Text::~Text() -{ - if(kind == TEXT_TEXT) - delete chars; - else if(kind == TEXT_NUM) - delete chars; -} - /* --- ERASE TEXT: --- */ void diff --git a/src/texture.cpp b/src/texture.cpp index 0051368dd..7773b7f14 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "SDL.h" #include "SDL_image.h" #include "texture.h" @@ -163,6 +164,17 @@ Surface::reload() Surface::~Surface() { +#ifdef DEBUG + bool found = false; + for(std::list::iterator i = surfaces.begin(); i != surfaces.end(); + ++i) { + if(*i == this) { + found = true; break; + } + } + if(!found) + printf("Error: Surface freed twice!!!\n"); +#endif surfaces.remove(this); delete impl; } diff --git a/src/title.cpp b/src/title.cpp index 4064e9705..cb3a512dc 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -362,6 +362,7 @@ void title(void) delete bkg_title; delete logo; + delete img_choose_subset; } // EOF // diff --git a/src/world.cpp b/src/world.cpp index e1795c0e2..fb9d49b74 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -101,6 +101,10 @@ World::~World() { for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i) delete *i; + + for (ParticleSystems::iterator i = particle_systems.begin(); + i != particle_systems.end(); ++i) + delete *i; delete level; } diff --git a/src/world.h b/src/world.h index 3399e03c8..62ca1d690 100644 --- a/src/world.h +++ b/src/world.h @@ -57,7 +57,8 @@ public: std::vector upgrades; std::vector bullets; - std::vector particle_systems; + typedef std::vector ParticleSystems; + ParticleSystems particle_systems; public: static World* current() { return current_; } diff --git a/src/worldmap.cpp b/src/worldmap.cpp index cfc03be9b..00c3a851e 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -674,7 +674,7 @@ WorldMap::update(float delta) if (dir != NONE) { tux->set_direction(dir); - tux->update(delta); + //tux->update(delta); } std::cout << "Walk to dir: " << dir << std::endl; @@ -724,8 +724,8 @@ WorldMap::update(float delta) } else { - tux->set_direction(input_direction); tux->update(delta); + tux->set_direction(input_direction); } Menu* menu = Menu::current(); @@ -866,6 +866,9 @@ WorldMap::display() delta *= 1.3f; + if (delta > 10.0f) + delta = .3f; + last_update_time = update_time; update_time = st_get_ticks(); -- 2.11.0