projects
/
supertux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8093f21
)
Fix minor memory leaks
author
Tim Goya
<tuxdev103@gmail.com>
Sun, 7 Oct 2007 19:25:34 +0000
(19:25 +0000)
committer
Tim Goya
<tuxdev103@gmail.com>
Sun, 7 Oct 2007 19:25:34 +0000
(19:25 +0000)
SVN-Revision: 5163
src/game_session.cpp
patch
|
blob
|
history
src/main.cpp
patch
|
blob
|
history
src/object_factory.cpp
patch
|
blob
|
history
src/object_factory.hpp
patch
|
blob
|
history
src/options_menu.cpp
patch
|
blob
|
history
diff --git
a/src/game_session.cpp
b/src/game_session.cpp
index
f1b6108
..
0a61cd3
100644
(file)
--- a/
src/game_session.cpp
+++ b/
src/game_session.cpp
@@
-166,6
+166,7
@@
GameSession::~GameSession()
delete capture_demo_stream;
delete playback_demo_stream;
delete demo_controller;
delete capture_demo_stream;
delete playback_demo_stream;
delete demo_controller;
+ free_options_menu();
current_ = NULL;
}
current_ = NULL;
}
diff --git
a/src/main.cpp
b/src/main.cpp
index
ade5d5d
..
84160c7
100644
(file)
--- a/
src/main.cpp
+++ b/
src/main.cpp
@@
-582,7
+582,6
@@
int main(int argc, char** argv)
delete main_loop;
main_loop = NULL;
delete main_loop;
main_loop = NULL;
- free_options_menu();
unload_shared();
quit_audio();
unload_shared();
quit_audio();
diff --git
a/src/object_factory.cpp
b/src/object_factory.cpp
index
5335140
..
fe89724
100644
(file)
--- a/
src/object_factory.cpp
+++ b/
src/object_factory.cpp
@@
-27,12
+27,10
@@
#include "object_factory.hpp"
#include "math/vector.hpp"
#include "object_factory.hpp"
#include "math/vector.hpp"
-Factories* object_factories = 0;
-
GameObject* create_object(const std::string& name, const lisp::Lisp& reader)
{
GameObject* create_object(const std::string& name, const lisp::Lisp& reader)
{
- Factor
ies::iterator i = object_factories->
find(name);
- if(i ==
object_factories->
end()) {
+ Factor
y::Factories::iterator i = Factory::get_factories().
find(name);
+ if(i ==
Factory::get_factories().
end()) {
std::stringstream msg;
msg << "No factory for object '" << name << "' found.";
throw std::runtime_error(msg.str());
std::stringstream msg;
msg << "No factory for object '" << name << "' found.";
throw std::runtime_error(msg.str());
diff --git
a/src/object_factory.hpp
b/src/object_factory.hpp
index
a6e4310
..
0e0d0d3
100644
(file)
--- a/
src/object_factory.hpp
+++ b/
src/object_factory.hpp
@@
-37,10
+37,14
@@
public:
* Remember to delete the objects later
*/
virtual GameObject* create_object(const lisp::Lisp& reader) = 0;
* Remember to delete the objects later
*/
virtual GameObject* create_object(const lisp::Lisp& reader) = 0;
-};
-typedef std::map<std::string, Factory*> Factories;
-extern Factories* object_factories;
+ typedef std::map<std::string, Factory*> Factories;
+ static Factories &get_factories()
+ {
+ static Factories object_factories;
+ return object_factories;
+ }
+};
GameObject* create_object(const std::string& name, const lisp::Lisp& reader);
GameObject* create_object(const std::string& name, const Vector& pos);
GameObject* create_object(const std::string& name, const lisp::Lisp& reader);
GameObject* create_object(const std::string& name, const Vector& pos);
@@
-57,10
+61,12
@@
class INTERN_##CLASS##Factory : public Factory \
public: \
INTERN_##CLASS##Factory() \
{ \
public: \
INTERN_##CLASS##Factory() \
{ \
-
if(object_factories == 0)
\
-
object_factories = new Factories;
\
+
get_factories()[NAME] = this;
\
+
}
\
\
\
- object_factories->insert(std::make_pair(NAME, this)); \
+ ~INTERN_##CLASS##Factory() \
+ { \
+ get_factories().erase(NAME); \
} \
\
virtual GameObject* create_object(const lisp::Lisp& reader) \
} \
\
virtual GameObject* create_object(const lisp::Lisp& reader) \
diff --git
a/src/options_menu.cpp
b/src/options_menu.cpp
index
c4c7ac9
..
93ab43d
100644
(file)
--- a/
src/options_menu.cpp
+++ b/
src/options_menu.cpp
@@
-158,14
+158,13
@@
OptionsMenu::menu_action(MenuItem* item)
Menu* get_options_menu()
{
Menu* get_options_menu()
{
- //
if(options_menu == NULL)
+ //
static OptionsMenu menu;
options_menu = new OptionsMenu();
options_menu = new OptionsMenu();
-
return options_menu;
}
void free_options_menu()
{
delete options_menu;
return options_menu;
}
void free_options_menu()
{
delete options_menu;
- options_menu =
NULL
;
+ options_menu =
0
;
}
}