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

imgui IM_ASSERT(g.FrameScopeActive) failure #113

Closed
astroesteban opened this issue Jan 2, 2020 · 17 comments
Closed

imgui IM_ASSERT(g.FrameScopeActive) failure #113

astroesteban opened this issue Jan 2, 2020 · 17 comments

Comments

@astroesteban
Copy link

astroesteban commented Jan 2, 2020

Compiler: Visual Studio Community 2019 (MSVC 16)
Operating System: Windows 10 64-bit

My Issue/Question:

When running my application in x64-Debug I get:
Assertion failed: g.FrameScopeActive, file C:\vcpkg\buildtrees\imgui\src\v1.73-a85d24b4b8\imgui.cpp, line 5400
only when I add ImGui::Begin and ImGui::End calls to my source file.

I am attempting to start a new C++ project using vcpkg, CMake, and Visual Studio on windows. I installed the following packages through vcpkg:

  • imgui-sfml:x64-windows v2.1
  • imgui:x64-windows v1.73-1
  • sfml:x64-windows v2.5.1-4

In my CMakeLists.txt I include the following:

...
find_package(SFML CONFIG COMPONENTS REQUIRED windows graphics system)
find_package(imgui CONFIG REQUIRED)
find_package(ImGui-SFML CONFIG REQUIRED)
...
add_executable(main app/main.cpp)
target_link_libraries(main
                                PRIVATE imgui::imgui
                                              ImGui-SFML::ImGui-SFML
                                             sfml-system
                                             sfml-window
                                             sfml-graphics)

My main.cpp file consists of the following:

#include <imgui.h>
#include <imgui-SFML.h>

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main()
{
	// Setup ImGui context
	ImGui::CreateContext();
	sf::RenderWindow window(sf::VideoMode(640, 480), "Test GUI");
	ImGui::SFML::Init(window);

	sf::Clock deltaClock;

	while (window.isOpen()) {
		sf::Event event{};
		while (window.pollEvent(event)) {
			ImGui::SFML::ProcessEvent(event);

			if (event.type == sf::Event::Closed) { window.close(); }
		}

		ImGui::SFML::Update(window, deltaClock.restart());

		ImGui::Begin("Test Begin");
                ImGui::Button("Test Button");
		ImGui::End();

		window.clear();
		ImGui::SFML::Render(window);
		window.display();
	} //end while

	ImGui::SFML::Shutdown();
}

When running my application in Visual Studio using the x64-Debug configuration I immediately get the following assertion failure for IM_ASSERT(g.FrameScopeActive). This only happens when I add the lines

ImGui::Begin("Test Begin");
ImGui::Button("Test Button");
ImGui::End();

Without them I get a running black window (first image below).

I have been unable to find a solution to this problem. I am unsure if this is an issue with ImGui-SFML or ImGui itself. Any help with this would be greatly appreciated. Thank you!

Screenshots/Video
image
error_2

@eliasdaler
Copy link
Contributor

eliasdaler commented Jan 6, 2020

Did you try to run minimal example from README.md? Does it work?

This line looks suspicious - you don't need to do it:

ImGui::CreateContext();

Also please check with debugger that ImGui::NewFrame really gets called. Maybe vcpkg package is not correct and patches something out...

@reworks-org
Copy link

Running the example also triggers this for me:
IM_ASSERT(g.WithinFrameScope); // Forgot to call ImGui::NewFrame()

@astroesteban
Copy link
Author

I ran the minimal example from the README and still get the same result. I don't think ImGui::NewFrame() is actually being called.

@eliasdaler
Copy link
Contributor

Can you please debug why it doesn't get called? At the moment I'm not able to reproduce this on my machine.

See the call to ImGui::NewFrame here: https:/eliasdaler/imgui-sfml/blob/master/imgui-SFML.cpp#L455

You need to make sure that this ImGui::SFML::Update gets called before any ImGui::Begin calls

@chenzdshao
Copy link

I encountered the same issue!

@eliasdaler
Copy link
Contributor

@chenzdshao can you please debug it a bit as I've described in my previous comment?

@chenzdshao
Copy link

@eliasdaler When I build and link ImGui-SFML.lib with vcpkg or cmake, here comes the error. When I compile and link imgui-SFML.cpp manually, the error disappears!

@eliasdaler
Copy link
Contributor

This means there are some problems with imgui-sfml's vcpkg package, and so the issue should probably be created in vcpkg repo...

@astroesteban
Copy link
Author

I encounter the same thing as @chenzdshao. I will open a new issue in the vcpkg repo.

@JackBoosY
Copy link
Contributor

JackBoosY commented Jan 15, 2020

After debugging, I found that there are multiple variable GImGui, the first variable is initialized, and the second variable is used subsequently.
I don't know why .I can reproduce it in Visual Studio 2019, but not in Visual Studio 2017.

Anyone can help me?

@eliasdaler
Copy link
Contributor

Might be something to do with linking and having multiple copies of one static object.
Can you try to link imgui-sfml statically?

@JackBoosY
Copy link
Contributor

@esduran Why is GimGui not set as a static variable to avoid this situation?

@eliasdaler
Copy link
Contributor

This is not something that I can control - it's an ImGui thing... Both static and dynamic linking work fine for me if I compile sources myself. vcpkg does something wrong, I can't tell what...

@astroesteban
Copy link
Author

The issue is also opened in vcpkg.
I'll go ahead and compile the sources myself as well.

@Eric-Ackles
Copy link

The vcpkg port of imgui enforces to build it as a static library. Its portfile.cmake has a vcpkg_check_linkage(ONLY_STATIC_LIBRARY) command.

But imgui-sfml is built as dll by vcpkg (default triplet). Then your executable and the dll will be linked to the static library twice.

https://stackoverflow.com/questions/31209693/static-library-linked-two-times

@eliasdaler
Copy link
Contributor

Then maybe ImGui-SFML should only be build as static lib as well?

@eliasdaler
Copy link
Contributor

Looks like it's been fixed in vcpkg package.

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

No branches or pull requests

6 participants