From 3de68c43466f8730d45058b3bb2695df1a9c9de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Fri, 16 Nov 2018 22:01:40 +0100 Subject: [PATCH] Fix event objects not being freed --- src/gui/game/GameController.cpp | 21 ++++++++++++++------- src/lua/LuaScriptInterface.cpp | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 8bc4e525f..45eafdf96 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -622,12 +622,14 @@ void GameController::CutRegion(ui::Point point1, ui::Point point2, bool includeP bool GameController::MouseMove(int x, int y, int dx, int dy) { - return commandInterface->HandleEvent(LuaEvents::mousemove, new MouseMoveEvent(x, y, dx, dy)); + MouseMoveEvent ev(x, y, dx, dy); + return commandInterface->HandleEvent(LuaEvents::mousemove, &ev); } bool GameController::MouseDown(int x, int y, unsigned button) { - bool ret = commandInterface->HandleEvent(LuaEvents::mousedown, new MouseDownEvent(x, y, button)); + MouseDownEvent ev(x, y, button); + bool ret = commandInterface->HandleEvent(LuaEvents::mousedown, &ev); if (ret && yGetPlacingSave() && !gameView->GetPlacingZoom()) { ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y)); @@ -649,7 +651,8 @@ bool GameController::MouseDown(int x, int y, unsigned button) bool GameController::MouseUp(int x, int y, unsigned button, char type) { - bool ret = commandInterface->HandleEvent(LuaEvents::mouseup, new MouseUpEvent(x, y, button, type)); + MouseUpEvent ev(x, y, button, type); + bool ret = commandInterface->HandleEvent(LuaEvents::mouseup, &ev); if (type) return ret; if (ret && foundSignID != -1 && yGetPlacingSave()) @@ -707,17 +710,20 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type) bool GameController::MouseWheel(int x, int y, int d) { - return commandInterface->HandleEvent(LuaEvents::mousewheel, new MouseWheelEvent(x, y, d)); + MouseWheelEvent ev(x, y, d); + return commandInterface->HandleEvent(LuaEvents::mousewheel, &ev); } bool GameController::TextInput(String text) { - return commandInterface->HandleEvent(LuaEvents::textinput, new TextInputEvent(text)); + TextInputEvent ev(text); + return commandInterface->HandleEvent(LuaEvents::textinput, &ev); } bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - bool ret = commandInterface->HandleEvent(LuaEvents::keypress, new KeyEvent(key, scan, repeat, shift, ctrl, alt)); + KeyEvent ev(key, scan, repeat, shift, ctrl, alt); + bool ret = commandInterface->HandleEvent(LuaEvents::keypress, &ev); if (repeat) return ret; if (ret) @@ -796,7 +802,8 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c bool GameController::KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { - bool ret = commandInterface->HandleEvent(LuaEvents::keyrelease, new KeyEvent(key, scan, repeat, shift, ctrl, alt)); + KeyEvent ev(key, scan, repeat, shift, ctrl, alt); + bool ret = commandInterface->HandleEvent(LuaEvents::keyrelease, &ev); if (repeat) return ret; if (ret) diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index f99e554ad..fd7d93959 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3349,7 +3349,8 @@ void LuaScriptInterface::OnTick() lua_setfield(l, -2, "NUM_PARTS"); } lua_pop(l, 1); - HandleEvent(LuaEvents::tick, new TickEvent()); + TickEvent ev; + HandleEvent(LuaEvents::tick, &ev); } int LuaScriptInterface::Command(String command)