Skip to content

Fix a rare crash on shutdown due to MidiInput / CriticalSection destruction order#1669

Open
emezeske wants to merge 1 commit into
juce-framework:developfrom
emezeske:midi-input-fix
Open

Fix a rare crash on shutdown due to MidiInput / CriticalSection destruction order#1669
emezeske wants to merge 1 commit into
juce-framework:developfrom
emezeske:midi-input-fix

Conversation

@emezeske

@emezeske emezeske commented Jun 9, 2026

Copy link
Copy Markdown

This crash presents as:

EXCEPTION_ACCESS_VIOLATION_WRITE / 0x24: Fatal Error: EXCEPTION_ACCESS_VIOLATION_WRITE / 0x24
?, in RtlpWaitOnCriticalSection
?, in RtlpEnterCriticalSectionContended
?, in RtlEnterCriticalSection
?, in juce::AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage
?, in juce::MidiInput::Impl::consume'::8'::::operator()
...
(20 additional frame(s) were not displayed)

It's due to the order in which enabledMidiInputs and midiCallbackLock are declared in the header: midiCallbackLock is destroyed before enabledMidiInputs. So the midi input callback can race and access the already-destroyed CriticalSection, causing this crash.

…icalSection object they reference is destroyed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@juce-push-bot

Copy link
Copy Markdown
Collaborator

This pull request has been mentioned on The JUCE Forum. There might be relevant details there:

https://forum.juce.com/t/crash-fix-a-rare-crash-on-shutdown-due-to-midiinput-criticalsection-destruction-order/68956/1

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants