ImGui works with Multiple Windows on multiple screens with one draw() call, but not with two

Hey Embers,

I switched to the 0.9.3dev branch of Cinder and have phased out AntTweakBar in favor of Dear ImGui. But the application crashes when using multiple windows, two draw() calls, and moving the ImGui rendering window across two different screens.

Specifically on line 5380 in imgui.cpp:

IM_ASSERT(g.WithinFrameScope); // Forgot to call ImGui::NewFrame()

To narrow down the problem I lightly modified the BasicAppMultiWindowApp Cinder Sample app. Here, there’s no crash. I render ImGui in one of the two windows, moving them across both screens - no problem.

In a new sandbox project, I split the draw callback (as opposed to a unified one in BasicAppMultiWindowApp) as suggested by @lithium, like so:

ci::app::Window::Format test;
test.title( "Second Window" ).pos( {100, 100} );
mWindowSecondary = ci::app::App::get()->createWindow( test );

mWindowPrimary->getSignalDraw().connect( std::bind( &SandboxPerformance::drawPrimary, this ) );
mWindowSecondary->getSignalDraw().connect( std::bind( &SandboxPerformance::drawSecondary, this ) );

auto options = ImGui::Options().window( mWindowPrimary );
ImGui::Initialize( options );

But now, unlike BasicAppMultiWindowApp, the application crashes when I render any ImGui elements in the primary window and it crosses into a different screen. Is there some context sharing or something going on I don’t get?

I also noticed that binding the primary draw call doesn’t appear to unbind the existing call to plain draw(), which surprises me a tad. But to be honest I’m a bit clueless here given how similar the single draw() call and dual draw() call approach appears.

I wonder if this is related to this topic?

Thanks in advance,
Gazoo

I wonder if this is related to this topic ?

That was what came to my mind when I started reading your message. However, in that case I don’t think I was wanting to actually use ImGui in both windows, only in one of them, but I was getting issues/crashes in that case when I had two open windows in the app; even more flaky when I moved one of the windows to a separate display. (I addressed my issues with a few PRs at the time)

Sorry, I don’t think I’ve tried making an application that had two windows, where both are interacting with and/or rendering ImGui…

@totalgee - I appreciate your response.

My initial post was perhaps not clear enough on this point, but I only have one single window in which I render and interact with ImGui. The second window has no ImGui functionality.

Despite this, I experience crashes when the window with ImGui moves between two screens and I use the getSignalDraw() call to have 2 separate drawing functions, i.e. one per window.

If - instead - I rely on a singular draw() and branch inside it, depending on the window it’s being triggered for, then there’s no crash. So something must be different between the two approaches and I’m currently not clear on what. :frowning: