Skip to content

Fix events.onexit callbacks accessing a disposed core and crashing#4638

Open
YoshiRulz wants to merge 1 commit intomasterfrom
onexit-crash-fix
Open

Fix events.onexit callbacks accessing a disposed core and crashing#4638
YoshiRulz wants to merge 1 commit intomasterfrom
onexit-crash-fix

Conversation

@YoshiRulz
Copy link
Member

@YoshiRulz YoshiRulz commented Feb 24, 2026

Dead simple, and doesn't interfere with running onexit callbacks when individual scripts are stopped.

@YoshiRulz YoshiRulz added the Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API) label Feb 24, 2026
@YoshiRulz YoshiRulz linked an issue Feb 24, 2026 that may be closed by this pull request
@YoshiRulz YoshiRulz requested a review from SuuperW February 24, 2026 14:52
Copy link
Contributor

@SuuperW SuuperW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly doing the same thing that my PR does, but it is making an exception for Lua rather than a generic solution for any tools that may end up with a similar issue. As I've stated, I prefer the generic solution. Do you have a reason to prefer making an exception for Lua? I don't think this one is meaningfully simpler.

But there is one issue with the way you've done this: If a Lua script causes the restart then exit events will get called without the scripts being stopped (or re-started). This will leave scripts in an undefined state. You need to check LuaImp.IsRebootingCore.

doesn't interfere with running onexit callbacks when individual scripts are stopped

Did mine? I'm not aware of any issues with my PR.

public void CallStateSaveCallbacks(string userFriendlyStateName)
=> LuaImp.CallSaveStateEvent(userFriendlyStateName);

public void CallScriptExitCallbacks()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the purpose of this needs to be documented. Calling the exit event without stopping the script is a weird thing to do, and that should be noted along with why it's done here.

Alternatively, you could do what I did and actually stop the scripts (renaming the method accordingly). Just keep a list of which ones were running so they can be started again in restart.

if (saveMovieResult == TryAgainResult.Canceled) return false;
}

if (Tools.Has<LuaConsole>()) Tools.LuaConsole.CallScriptExitCallbacks(); // important to do this here with the stale `IEmulator`, see https://github.com/TASEmulators/BizHawk/issues/4629
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emulator isn't stale yet, it is still current.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when rebooting emulator core

2 participants