c2749d3b49
WebKit's AddScriptMessageHandler calls RunScript internally, which yields the event loop via DoYieldFor. When this runs inside a nested event loop (e.g., Update PCB from Schematic's modal dialog), JSC crashes in sanitizeStackForVM. The previous fix used CallAfter to defer handler registration, but CallAfter events fire immediately in the modal dialog's event loop, creating a tight busy-wait that freezes the UI. Replace CallAfter re-deferral with a wxTimer that retries every 200ms until the main event loop is active. Also guard AddMessageHandler's late-registration path with the same nested loop check so handlers added after init are safe too. Fixes https://gitlab.com/kicad/code/kicad/-/issues/23423