api-issue-tracker
api-issue-tracker copied to clipboard
HtmlDialog::execute_script() crash on Mac when we quit
- SketchUp/LayOut Version: tested with SketchUp 2017 and 2020
- OS Platform: Mac OS X only
On Mac, we cannot call HtmlDialog::execute_script() in a UI.set_timer() callback. It works fine, expect when the user presses Command-Q or chooses the Quit command. At that point it crashes the application.
I think what occurs is that SketchUp first shuts down the JavaScript engine, and then it invokes any pending timer, and only then it invokes AppObserver::onQuit. So the Ruby code invoked by the timer calls execute_script(), as it always does---that's the purpose of this timer. However, in this case it crashes because the JavaScript engine is already down. It's also not possible to add a workaround "onQuit was called so don't do anything" because onQuit is only called afterwards.
FWIW, a workaround is to remove (as much as possible) all the calls to UI.set_timer(), and replace them with JavaScript timers using an action callback to call Ruby. It doesn't change much, except that nothing will be invoked after the JavaScript engine stops.
(I cannot at the moment get a verified reproducer because I don't have access to a Mac. If you don't manage to reproduce, I will try to do so, but it will take time. I suspect that it always crashes just by following the steps described above; if needed try to use a very low or null timeout, to make sure it is called as often as possible.)
SU-46006