Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS runtime warnings regarding access of NSView/NSWindow properties from a non-main thread #7393

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tim-rex
Copy link
Contributor

@tim-rex tim-rex commented Mar 12, 2024

Xcode Version 15.3 (15E204a)

Resolve Xcode runtime warnings regarding access of NSView/NSWindow properties from a non-main thread
This issue presents when rendering from a thread that is other than the window thread, more easily reproduced when disabling vsync

This commit aims to populate the relevant data into backend_data, by way of dispatch_async (ocurring on the main thread). Those particular backend data items are protected by an NSlock

There may be more elegant ways to do this

The warnings observed are as follows:
Main Thread Checker

imgui/backends/imgui_impl_osx.mm:608 -[NSView window] must be used from main thread only
imgui/backends/imgui_impl_osx.mm:608 -[NSWindow backingScaleFactor] must be used from main thread only
imgui/backends/imgui_impl_osx.mm:609 -[NSView bounds] must be used from main thread only

…operties from a non-main thread

This issue presents when rendering from a thread that is other than the window thread, more easily reproduced when disabling vsync

This commit aims to populate the relevant data into backend_data, by way of dispatch_async (ocurring on the main thread). Those particular backend data items are protected by an NSlock

There may be more elegant ways to do this

Main Thread Checker
imgui/backends/imgui_impl_osx.mm:608 -[NSView window] must be used from main thread only
imgui/backends/imgui_impl_osx.mm:608 -[NSWindow backingScaleFactor] must be used from main thread only
imgui/backends/imgui_impl_osx.mm:609 -[NSView bounds] must be used from main thread only
…operties from a non-main thread

This issue presents when rendering from a thread that is other than the window thread, more easily reproduced when disabling vsync

This commit aims to populate the relevant data into backend_data, by way of dispatch_async (ocurring on the main thread). Those particular backend data items are protected by an NSlock

There may be more elegant ways to do this

Main Thread Checker
imgui/backends/imgui_impl_osx.mm:608 -[NSView window] must be used from main thread only
imgui/backends/imgui_impl_osx.mm:608 -[NSWindow backingScaleFactor] must be used from main thread only
imgui/backends/imgui_impl_osx.mm:609 -[NSView bounds] must be used from main thread only
@ocornut
Copy link
Owner

ocornut commented Mar 12, 2024

Also see #6528

…anitiser concerns

This is a little nasty..
I'm trying to keep all changes localised to imgui_impl_osx.mm

Ideally the ImGui_IO_lock would live within ImGuiIO but I didn't want to muddy the waters

Perhaps better if this lock primitive is delivered through BackendPlatformUserData, and only used where provided

This change requires the client platform to explicitly lock the primitive from outside of ImGui around ImGui::NewFrame specifically, and additionally from anywhere on the client side (external to ImGui) that concurrently hooks into ImGuiIO

That requires the client to define an extern lock (and use it appropriately)
 extern NSlock *ImGui_IO_lock

If this lock were native to ImGui we could have ImGui::NewFrame() handle the lock on our behalf, negating the need for client side locking
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.

None yet

2 participants