Permalink
Browse files

Fixed some memory leaks in input_manager, and disabled copy construct…

…ors because these classes are not safe to copy.
  • Loading branch information...
1 parent 3291bd7 commit 2f0546da170dd31ae71e36b1ae855ef8b6a48951 luqui committed Aug 6, 2008
Showing with 18 additions and 1 deletion.
  1. +18 −1 soylent/GoD/input_manager.h
@@ -25,6 +25,11 @@ struct Input_Command
SDL_Event *events;
int numEvents;
+
+private:
+ // no copying!
+ Input_Command(const Input_Command&);
+ Input_Command& operator= (const Input_Command&);
};
class Input_Manager
@@ -41,6 +46,10 @@ class Input_Manager
}
~Input_Manager()
{
+ for (int i = 0; i < SDLK_LAST; i++) {
+ delete keyDown_Bindings[i];
+ delete keyUp_Bindings[i];
+ }
delete[] keyDown_Bindings;
delete[] keyUp_Bindings;
}
@@ -51,9 +60,14 @@ class Input_Manager
switch(command->events[i].type)
{
case SDL_KEYDOWN:
+ // maybe instead of unregistering the previous callback
+ // we could assign it a new "Combination_Command" instance
+ // which combines the effects of two commands.
+ delete keyDown_Bindings[command->events[i].key.keysym.sym];
keyDown_Bindings[command->events[i].key.keysym.sym] = command;
break;
case SDL_KEYUP:
+ delete keyUp_Bindings[command->events[i].key.keysym.sym];
keyUp_Bindings[command->events[i].key.keysym.sym] = command;
break;
default:
@@ -90,6 +104,9 @@ class Input_Manager
Input_Command **keyDown_Bindings;
Input_Command **keyUp_Bindings;
+ // no copying!
+ Input_Manager(const Input_Manager&);
+ Input_Manager& operator= (const Input_Manager&);
};
-#endif
+#endif

0 comments on commit 2f0546d

Please sign in to comment.