From 4923ee400960871b29dd72d139e196abc5f7535c Mon Sep 17 00:00:00 2001 From: Hirek Date: Thu, 9 Jan 2025 16:07:57 +0100 Subject: [PATCH] Final fix for missing getCommands function inside abstractscreenrenderer --- PyInt.cpp | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/PyInt.cpp b/PyInt.cpp index 4d6149c7..dc942da9 100644 --- a/PyInt.cpp +++ b/PyInt.cpp @@ -108,27 +108,33 @@ void render_task::run() { // get commands from renderer auto *commandsPO = PyObject_CallMethod(m_renderer, "getCommands", nullptr); - std::vector commands = python_external_utils::PyObjectToStringArray(commandsPO); - Py_DECREF(commandsPO); + if (commandsPO != nullptr) + { + std::vector commands = python_external_utils::PyObjectToStringArray(commandsPO); - // we perform any actions ONLY when there are any commands in buffer - if (!commands.empty()) - { - for (const auto &command : commands) + Py_DECREF(commandsPO); + // we perform any actions ONLY when there are any commands in buffer + if (!commands.empty()) { - auto it = simulation::commandMap.find(command); - if (it != simulation::commandMap.end()) + for (const auto &command : commands) { - // command found - command_data cd; - cd.command = it->second; - cd.action = GLFW_PRESS; - simulation::Commands.push(cd, static_cast(command_target::vehicle) | 1); // player train is always 1 + auto it = simulation::commandMap.find(command); + if (it != simulation::commandMap.end()) + { + // command found + command_data cd; + cd.command = it->second; + cd.action = GLFW_PRESS; + simulation::Commands.push(cd, static_cast(command_target::vehicle) | 1); // player train is always 1 + } + else + ErrorLog("Python: Command [" + command + "] not found!"); } - else - ErrorLog("Python: Command [" + command + "] not found!"); - } - } + } + + } + + }