#15272·mame

Periodic Lua callback not called at all on macOS and Windows when the debug window out of focus

Author: janko-jjCreated Apr 27, 2026Updated Sep 28, 2026

MAME version

0.287 (mame0287-405-g9783c10eadb)

System information

  • macOS Sequoia 15.7.3, CPU M1 Max (Macbook Pro 16 inch 2021), 32GB RAM
  • Windows 11: see #14600 (from November 2025, the issue is not only recent)

INI configuration details

IniArchive.zip

Emulated system/software

It is believed: any, when a native (macOS or Windows) debugger window is opened and not in focus, but tested with tbblue

Incorrect behaviour

The Lua's callback function registered in the plugin with emu.register_periodic is in important use cases not called at all, neither on macOS, nor on Windows (as reported in #14600)

As soon as the debug window is open, but not in focus, no calls into the function happen, neither on macOS, nor on Windows.

Attached is a cperiodic plugin written to demonstrate the issue, applicable for both systems:

plugin_cperiodic.zip

Expected behaviour

The Lua's callback function registered in the plugin with emu.register_periodic should be called often enough times per second on Windows and macOS, even when the debug window is opened but not topmost and not in focus.

Reason: to allow MAME debugging session being controlled by an external GUI program, the user expects to control MAME from the external GUI, in which various debugging information is displayed, or the state of debugged machine changed. During all that time MAME windows aren't in focus, and when the periodic function is not called, the interaction via sockets can't happen.

Steps to reproduce

  1. Add the attached cperiodic plugin to the plugin directory
  2. Run MAME from the OS's command line console with -d and -plugin cperiodic in the command line (make sure no other plugins that could interfere are activated by default)
  3. Wait for the guest system to boot
  4. Observe that there are around of 50 calls per second printed in the console (the plugin prints the count of the calls once per second, if there are calls).
  5. Press the ~ to pop up the debugger window
  6. Click somewhere outside of the MAME debugger window and MAME
  7. Stop moving the mouse
  8. Observe that the calls to periodic completely stop (no new output into the console):
Image

In the picture above we see that during 17 seconds no calls happened (as the plugin can't write a new line during the 17 seconds), then the user moves the mouse in the window, so the displayed number of calls is logged during the 17-th second).

The similar or same behavior can be observed on Windows too, where no calls to Lua periodic callback happen when the debug window is not in focus and the mouse is not moved.

Contrary to that behavior on both macOS and Windows, tunder the same conditions, on QT MAME build on Linux around 20 calls happen per second (the difference in the implementations will be discussed later in this report).

Additional details

The causes are narrowed down to the way the main loop for processing both the window messages and call Lua's periodic is implemented. In the sources we see:

  1. for macOS ( src/osd/modules/debugger/debugosx.mm#L164 ):
c
        // get and process messages
        NSEvent *ev = [NSApp nextEventMatchingMask:NSEventMaskAny
                             untilDate:[NSDate distantFuture]
                                    inMode:NSDefaultRunLoopMode
                               dequeue:YES];
  1. for Windows ( src/osd/modules/debugger/debugwin.cpp#L209 ):
c
	MSG message;
	GetMessage(&message, nullptr, 0, 0)

Both of those remain "stuck" under the described conditions (other application is in focus, not enough mouse movements).

To compare with the "somewhat working" case: the current QT implementation has ( src/osd/modules/debugger/debugqt.cpp#L174 ):

c
	osd_sleep(osd_ticks_per_second() / 1000 * 50);
	qApp->processEvents(QEventLoop::AllEvents, 1);

Note that this handling is also suboptimal and probably different from what was expected: the above sleep constant results only in 20 calls per second observed, as the sleep time between two possible calls is whole 50ms. That is even less frequent than while the guest machine runs (when around 50 calls per second happen!) in spite of the fact that the guest machine doesn't run and the time is spent on the long sleeps instead.

The need for the existence of periodic calls is the wish to use VSCode with the appropriate extension(s) to provide advanced GUI-based debugging functionality (e.g. stepping through the source lines of the program, including C sources and observing the changes) where an extension could communicate with the plugin which uses a socket to receive the requests and respond. If the plugin doesn't get the periodic calls it can't respond to the requests when it should.

The hope is that the handling in all three cases could be improved as the fixes are already known for all the platforms and tested by various users in the Next community. (In the Next community there exists for years an advanced extension for "remote" source-level debugging which is able to communicate with various emulators and real hardware. A plugin which allows MAME to communicate with it exists, but the current blocking issue is the calls not happening. The plugin was written using the same principles that are used by gdbstub.)

(Just for completeness, even if we believe that the behavior could be reproduced with any system, as soon as the debugger window is opened and not in focus, the used command line for tests was: mame tbblue -bios v30204 -d -plugins -plugin console,cperiodic -video bgfx -bgfx_screen_chains unfiltered -window -skip_gameinfo -ui_active -nounevenstretch -aspect 2:1 -waitvsync -hard1 cspect-next-2gb.img the disk image can be downloaded from https://zxnext.uk/hosted/ (containing the content from the open source repo https://gitlab.com/thesmog358/tbblue/-/tree/master/ ) and the needed roms (GPL) are on https://github.com/Threetwosevensixseven/NexCreator/raw/master/bootroms/tbblue.zip )

For completeness, once again the link to the plugin to demonstrate the behavior: plugin_cperiodic.zip