imgui-sfml: imgui IM_ASSERT(g.FrameScopeActive) failure

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (10 by maintainers)

Most upvoted comments

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

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://github.com/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

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