Skip to content

Commit

Permalink
UPBGE: Fix mouse, keyboard and joystick python proxy.
Browse files Browse the repository at this point in the history
Previously all the python proxies for mouse, keyboard and
joystick was python owned and made that when the bge.logic
module was freed the proxies was freed too.
This case not appear as the bge.logic module is not freed
following the python behaviour, and that we manually delete
the mouse, keyboard and joystick at the end of the game
without noticed issues.
But with the refactor on joystick and the add remove feature,
the joystick python proxy was deleted twice, once from python
when replacing a joystick python proxy and a second time
manually from the game end.

To fix this issue the proxy creation which was using NewProxy(true)
is now replaced by GetProxy. In the same time the items in
the joystick list are done with PyList_SetItem instead of
PyList_SET_ITEM, which is more reference safer.
  • Loading branch information
youle31 committed Sep 19, 2016
1 parent 19f48ee commit b439be7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/gameengine/Ketsji/KX_PythonInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,11 +1451,11 @@ PyMODINIT_FUNC initGameLogicPythonBinding()
// Add keyboard, mouse and joysticks attributes to this module
BLI_assert(!gp_PythonKeyboard);
gp_PythonKeyboard = new SCA_PythonKeyboard(KX_GetActiveEngine()->GetInputDevice());
PyDict_SetItemString(d, "keyboard", gp_PythonKeyboard->NewProxy(true));
PyDict_SetItemString(d, "keyboard", gp_PythonKeyboard->GetProxy());

BLI_assert(!gp_PythonMouse);
gp_PythonMouse = new SCA_PythonMouse(KX_GetActiveEngine()->GetInputDevice(), KX_GetActiveEngine()->GetCanvas());
PyDict_SetItemString(d, "mouse", gp_PythonMouse->NewProxy(true));
PyDict_SetItemString(d, "mouse", gp_PythonMouse->GetProxy());

PyObject *joylist = PyList_New(JOYINDEX_MAX);
for (unsigned short i = 0; i < JOYINDEX_MAX; ++i) {
Expand Down Expand Up @@ -2229,7 +2229,7 @@ void updatePythonJoysticks(short (&addrem)[JOYINDEX_MAX])
DEV_Joystick *joy = DEV_Joystick::GetInstance(i);
if (joy && joy->Connected()) {
gp_PythonJoysticks[i] = new SCA_PythonJoystick(joy, i);
item = gp_PythonJoysticks[i]->NewProxy(true);
item = gp_PythonJoysticks[i]->GetProxy();
}
}
else if (addrem[i] == 2) {
Expand All @@ -2239,7 +2239,7 @@ void updatePythonJoysticks(short (&addrem)[JOYINDEX_MAX])
}
}

PyList_SET_ITEM(pythonJoyList, i, item);
PyList_SetItem(pythonJoyList, i, item);
}

Py_DECREF(gameLogic);
Expand Down

0 comments on commit b439be7

Please sign in to comment.