From d417bdc8a384d517307bb991cd7a0ccc059e9c7c Mon Sep 17 00:00:00 2001 From: John McCardle Date: Thu, 7 Mar 2024 09:49:24 -0500 Subject: [PATCH] Whoops, some issues with deleting timers. --- src/GameEngine.cpp | 7 ++++--- src/Timer.cpp | 17 +---------------- src/Timer.h | 2 -- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/GameEngine.cpp b/src/GameEngine.cpp index dfc202a..02f786d 100644 --- a/src/GameEngine.cpp +++ b/src/GameEngine.cpp @@ -72,12 +72,13 @@ void GameEngine::run() void GameEngine::manageTimer(std::string name, PyObject* target, int interval) { //std::cout << "Manage timer called. " << name << " " << interval << std::endl; - if (timers.find(name) != timers.end()) // overwrite existing + auto it = timers.find(name); + if (it != timers.end()) // overwrite existing { if (target == NULL || target == Py_None) // delete { - Py_DECREF(target); - timers.erase(name); + Py_DECREF(timers[name].target); + timers.erase(it); return; } } diff --git a/src/Timer.cpp b/src/Timer.cpp index c04ccf4..88eb597 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -2,26 +2,12 @@ Timer::Timer(PyObject* _target, int _interval, int now) : target(_target), interval(_interval), last_ran(now) -{ - //Py_INCREF(target); -} +{} Timer::Timer() : target(Py_None), interval(0), last_ran(0) {} -Timer::Timer(Timer& other) -: target(other.target), interval(other.interval), last_ran(other.last_ran) -{ - //Py_INCREF(target); -} - -Timer::~Timer() -{ - //if (target && target != Py_None) - // Py_DECREF(target); -} - bool Timer::test(int now) { if (!target || target == Py_None) return false; @@ -29,7 +15,6 @@ bool Timer::test(int now) { last_ran = now; PyObject* args = Py_BuildValue("(i)", now); - std::cout << PyUnicode_AsUTF8(PyObject_Repr(args)) << std::endl; PyObject_Call(target, args, NULL); return true; } diff --git a/src/Timer.h b/src/Timer.h index 0e01344..bc9b7dd 100644 --- a/src/Timer.h +++ b/src/Timer.h @@ -10,8 +10,6 @@ public: int interval; int last_ran; Timer(); // for map to build - Timer(Timer& other); // copy constructor Timer(PyObject*, int, int); - ~Timer(); bool test(int); };