Skip to content

Calling Context::load_texture with a write lock held to the InputState causes a deadlock #2064

@Ununoctium117

Description

@Ununoctium117

Describe the bug

Context::load_texture acquires a read lock to the context's InputState, which is unexpected. I discovered this by accidentally holding a handle from Context::input_mut for longer than necessary, and calling load_texture with it held. At time of writing, the lock is acquired here: https://github.com/emilk/egui/blob/master/crates/egui/src/context.rs#L755

To Reproduce
Steps to reproduce the behavior:

  1. Call Context::input_mut in your UI code to query user inputs.
  2. Later (perhaps in response to user action consumed with InputState::consume_key), call Context::load_texture, before the MappedRwLockWriteGuard from input_mut is dropped.

I can write a minimal working example later if needed, but hopefully this is clear enough.

Expected behavior
Texture loading code would not interact with InputState.

Screenshots
N/A

Desktop (please complete the following information):
This isn't OS specific.

Additional context
It seems strange that loading a texture would have anything to do with the user input, but this could reasonably be solved by documenting this behavior on Context::load_texture. It's easy enough to work around (just drop the lock guard earlier), but it's tricky to realize what's happening without debugging egui code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions