Environment:
I am encountering this bug on the Simulator on Windows 11. I have reproduced this behavior on SDK v2.5.0 and v2.6.2. I have not tested other environments (macOS or Linux). The crash does NOT happen on the device.
What the bug is:
I have found that then when I use pd->system->setButtonCallback()
, my program runs fine, but when I exit back out to the system Launcher, the Simulator crashes on the first button press. If I do not call setButtonCallback()
, then the Simulator does not crash after running my program.
How to reproduce:
I have verified this by adding an empty PDButtonCallbackFunction
to the C_API Hello World example and then calling setButtonCallback(). I am attaching a main.c that reproduces the error: main.c.zip (932 Bytes)
Some speculation:
setButtonCallback()
works and does what it's supposed to inside my game. So if you just run your game and then close the simulator, you'll never see the crash. But I think when a game exits, the key handler is not reset by the Simulator. So then on the next key press, the Simulator looks for a callback function that doesn't exist any more because your game has been unloaded, and that's the crash.
Two details support this theory:
- The crank and the system keys still work after the game exits. Only pressing the D-pad or A or B causes the crash, and those are the keys that are handled by the button callback.
- If the game sets the callback to NULL before exiting, then the Simulator no longer crashes, but it also doesn't respond to any input from the D-pad or A or B.
So basically, calling setButtonCallback()
sets the key handler for the whole Simulator, and it's not reset until the Simulator is restarted.