Can only add events to current context. #6199

Closed
opened 2023-02-26 12:27:11 +00:00 by tksuoran · 2 comments
tksuoran commented 2023-02-26 12:27:11 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.89.3 WIP (18923)
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: glfw / erhe
Operating System: Windows 10

My Issue/Question:

I am adding file dialog usage into my code. The code that uses the file dialog is like this:

if (ImGui::Button("Load Map")) {
    const auto path_opt = select_file();
    if (path_opt.has_value()) { // load map }
}
if (ImGui::Button("Save Map")) {
...

My select_file() uses Windows IFileOpenDialog which opens a new window on top of my glfw window. This triggers glfw focus callback event, which is happening in context that is something else than the main thread.

I am not sure how to deal with the glfw focus event. I would like to call m_imgui_context->IO.AddFocusEvent(focused != 0) (for my Window ImGui viewport). However, current ImGui does not allow this, if I happen to be using in different ImGui context.

I wonder what my options are:

  1. Queue all events when received from glfw, send them to ImGui when the context becomes current.
  2. Perhaps making GImGui thread_local might allow me to have a different ImGui context in the wndproc context?
  3. Can we somehow lift the Can only add events to current context restriction?

I'd really prefer removing the restriction on requiring context to be current in order to be able to send events to it. Any thoughts? Thanks!

**Version/Branch of Dear ImGui:** Version: 1.89.3 WIP (18923) Branch: docking **Back-end/Renderer/Compiler/OS** Back-ends: glfw / erhe Operating System: Windows 10 **My Issue/Question:** I am adding file dialog usage into my code. The code that uses the file dialog is like this: ```C++ if (ImGui::Button("Load Map")) { const auto path_opt = select_file(); if (path_opt.has_value()) { // load map } } if (ImGui::Button("Save Map")) { ... ``` My `select_file()` uses Windows `IFileOpenDialog` which opens a new window on top of my glfw window. This triggers glfw focus callback event, which is happening in context that is something else than the main thread. I am not sure how to deal with the glfw focus event. I would *like to* call `m_imgui_context->IO.AddFocusEvent(focused != 0)` (for my Window ImGui viewport). However, current ImGui does not allow this, if I happen to be using in different ImGui context. I wonder what my options are: 1. Queue all events when received from glfw, send them to ImGui when the context becomes current. 2. Perhaps making `GImGui` `thread_local` might allow me to have a different ImGui context in the wndproc context? 3. Can we somehow lift the `Can only add events to current context` restriction? I'd really prefer removing the restriction on requiring context to be current in order to be able to send events to it. Any thoughts? Thanks!
ocornut commented 2023-02-26 13:04:02 +00:00 (Migrated from github.com)

We should probably lift that constraint by storing a context pointer in IO. Would also be desirable for #5856

We should probably lift that constraint by storing a context pointer in IO. Would also be desirable for #5856
ocornut commented 2023-03-08 14:40:06 +00:00 (Migrated from github.com)

Fixed with 10ace22 by @Dragnalith

Fixed with 10ace22 by @Dragnalith
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6199
No description provided.