Oops, remove resource leak in the input wrapper.

This commit is contained in:
Jordan Milne 2013-01-12 15:38:22 -04:00
parent 5a6589af01
commit eb08f407d3
2 changed files with 12 additions and 22 deletions

View file

@ -28,21 +28,7 @@ namespace SFO
mMouseX(0) mMouseX(0)
{ {
_setupOISKeys(); _setupOISKeys();
_start();
}
InputWrapper::~InputWrapper()
{
if(mSDLWindow != NULL)
SDL_DestroyWindow(mSDLWindow);
mSDLWindow = NULL;
SDL_StopTextInput();
SDL_Quit();
}
bool InputWrapper::_start()
{
//get the HWND from ogre's renderwindow //get the HWND from ogre's renderwindow
size_t windowHnd; size_t windowHnd;
mWindow->getCustomAttribute("WINDOW", &windowHnd); mWindow->getCustomAttribute("WINDOW", &windowHnd);
@ -50,12 +36,11 @@ namespace SFO
//wrap our own event handler around ogre's //wrap our own event handler around ogre's
mSDLWindow = SDL_CreateWindowFrom((void*)windowHnd); mSDLWindow = SDL_CreateWindowFrom((void*)windowHnd);
if(mSDLWindow == NULL) assert(mSDLWindow != NULL);
return false;
//without this SDL will take ownership of the window and iconify it when //without this SDL will take ownership of the window and iconify it when
//we alt-tab away. //we alt-tab away.
SDL_SetWindowFullscreen(mSDLWindow, 0); //SDL_SetWindowFullscreen(mSDLWindow, 0);
//translate our keypresses into text //translate our keypresses into text
SDL_StartTextInput(); SDL_StartTextInput();
@ -91,14 +76,20 @@ namespace SFO
XFlush(display); XFlush(display);
} }
#endif #endif
return true; }
InputWrapper::~InputWrapper()
{
if(mSDLWindow != NULL)
SDL_DestroyWindow(mSDLWindow);
mSDLWindow = NULL;
SDL_StopTextInput();
SDL_Quit();
} }
void InputWrapper::capture() void InputWrapper::capture()
{ {
if(!_start())
throw std::runtime_error(SDL_GetError());
SDL_Event evt; SDL_Event evt;
while(SDL_PollEvent(&evt)) while(SDL_PollEvent(&evt))
{ {

View file

@ -35,7 +35,6 @@ namespace SFO
void warpMouse(int x, int y); void warpMouse(int x, int y);
private: private:
bool _start();
bool _handleWarpMotion(const SDL_MouseMotionEvent& evt); bool _handleWarpMotion(const SDL_MouseMotionEvent& evt);
void _wrapMousePointer(const SDL_MouseMotionEvent &evt); void _wrapMousePointer(const SDL_MouseMotionEvent &evt);