OSX Simulator stops calling C update callback when it returns 0

The docs state:

The update function should return a non-zero number to tell the system to update the display, or zero if update isn’t needed.

However, when running a PDX in the Simulator on OSX, the update callback will no longer be called after it returns 0. It seems that causing a window event on the Simulator itself will correct the issue, but I haven't thoroughly tested this.

This code demonstrates the issue:

#include "pd_api.h"

static int ret = 10;

int update(void * userdata) {
    PlaydateAPI * pd = userdata;
    pd->system->logToConsole("ret: %d", ret);
    return ret--;
}

#ifdef _WINDLL
__declspec(dllexport)
#endif
int eventHandler(PlaydateAPI * pd, PDSystemEvent event, uint32_t arg) {
    (void)arg;

    if (event == kEventInit) {
        pd->system->setUpdateCallback(update, pd);
    }

    return 0;
}

In the Simulator, this will count down to 0 and halt. On device, it correctly continues to log into the negatives.

Hello @grendell - this one has been bugging me too. Since you have a device - are you able to confirm if the or zero if update isn’t needed. mechanic works as intended on the HW? I.e. draw something, return 0, check that it doesn't get displayed on the screen until returning non-zero.

Hey @timboe, sure thing. I made a simple app with the following behavior:

  • Every time A is pressed, a square is drawn at a random screen location.
  • Every time A is pressed, the return value of update is toggled.

Running this on device, I can confirm that adding squares continues to work, even though visually you see them appear in pairs. This is in-line with the documentation.

1 Like

Yep, you're right, if the docs say the only effect that returning 0 has is that it doesn't update the display then we shouldn't be pausing the simulator. The problem is I was using the 0 return to signal an error instead of checking that an error message has been set. Fixed that!

1 Like