Segfault fixes. Switching scenes broke some assumptions. All PyObject calls from userspace now handle (discard) exceptions and return values.

This commit is contained in:
John McCardle 2024-03-08 12:09:09 -05:00
commit aa7f2ba605
5 changed files with 41 additions and 4 deletions

View file

@ -162,7 +162,16 @@ void GameEngine::sUserInput()
else if (currentScene()->key_callable != NULL && currentScene()->key_callable != Py_None)
{
PyObject* args = Py_BuildValue("(ss)", ActionCode::key_str(event.key.code).c_str(), actionType.c_str());
PyObject_Call(currentScene()->key_callable, args, NULL);
PyObject* retval = PyObject_Call(currentScene()->key_callable, args, NULL);
if (!retval)
{
std::cout << "key_callable has raised an exception. It's going to STDERR and being dropped:" << std::endl;
PyErr_Print();
PyErr_Clear();
} else if (retval != Py_None)
{
std::cout << "key_callable returned a non-None value. It's not an error, it's just not being saved or used." << std::endl;
}
}
else
{