Skip to content

Conversation

@juancampa
Copy link
Contributor

Problem

Originally reported by @emilk in #7652 (comment)

When a plugin creates a widget (e.g. during on_pass_end) and that widget gets hovered, egui will call on_widget_under_cursor, causing a deadlock because the plugin is still locked on the stack.

Fix

Added Mutex::try_lock which returns None immediately if the mutex can't be acquired.

This is only used for on_widget_under_cursor, which will now get skipped if its mutex is locked.

Since plugins can technically be locked from other threads (via TypedPluginHandle), the try_lock function is not used for the other plugin hooks so that they execute reliably (as they used to before this change). Whereas on_widget_under_cursor will be skipped if it happens that the plugin is locked externally. Small caveat but probably not an issue?

For example, a plugin does some background work and uses TypedPluginHandle to set the result back in the plugin state object. To set the result, it locks the plugin. If it happens that egui tries to run on_widget_under_cursor, it will be skipped.

  • I have followed the instructions in the PR template

@github-actions
Copy link

github-actions bot commented Jan 13, 2026

Preview available at https://egui-pr-preview.github.io/pr/7845-fix-plugin-deadlock
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@juancampa juancampa marked this pull request as ready for review January 13, 2026 20:06
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.

1 participant