Skip to content

Fix macOS toolbar crash - #30863

Merged
greglucas merged 1 commit into
matplotlib:mainfrom
lilfer:fix-macosx-toolbar-crash
Dec 15, 2025
Merged

greglucas merged 1 commit into
matplotlib:mainfrom
lilfer:fix-macosx-toolbar-crash

Conversation

@lilfer

@lilfer lilfer commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

PR summary

Closes #28513
Fixes a segmentation fault in the _macosx backend that occurs when closing figures.
In the original implementation of NavigationToolbar2, it relied on the window to hold the only strong reference to messagebox. The toolbar sometimes living longer than the window—and thus messagebox— resulted in the crash.
I'm still not sure why this crash seems to only occur when closing a figure that was created in the event loop.

Fix: NavigationToolbar2 now also retains messagebox.

I checked that messagebox is deallocated after a figure is closed and gc.collect() runs.

PR checklist

@tacaswell tacaswell added this to the v3.11.0 milestone Dec 15, 2025

@tacaswell tacaswell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense and I manually tested.

@greglucas
greglucas merged commit 9e210e8 into matplotlib:main Dec 15, 2025
33 of 38 checks passed
@greglucas

Copy link
Copy Markdown
Contributor

Thanks @lilfer! If you're in macos backend bug squashing mode, there are several other similar reference counting issues hanging around I think if you have any ideas for those too: https://github.com/matplotlib/matplotlib/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22GUI%3A%20MacOSX%22

@lilfer
lilfer deleted the fix-macosx-toolbar-crash branch December 15, 2025 21:39
andreas16700 added a commit to andreas16700/matplotlib that referenced this pull request Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Segfault when using close_event with macosx backend and tk

3 participants