Vcpkg: imgui-sfml IM_ASSERT failure

Created on 13 Jan 2020  Â·  28Comments  Â·  Source: microsoft/vcpkg

Describe the bug
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:

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>
#include <SFML/Graphics/CircleShape.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    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("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    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

Environment

  • OS: Windows 10
  • Compiler: Visual Studio Community 2019 with MSVC v142 - VS 2019 C++ x64/x96 build tools (v14.24)

To Reproduce
Steps to reproduce the behavior:

  1. ./vcpkg install imgui-sfml:x64-windows
  2. Create a basic CMakeLists with the ImGui-SFML repo's example main.cpp
  3. Run the application in x64 Debug and get the IM_ASSERT failure

Expected behavior
Expected to see an ImGui window with a button.

Additional context
This issue was initially opened directly in the ImGui-SFML repository, but after some experimentation it was determined that the issue exists in the vcpkg version.

port-bug

Most helpful comment

Dear All, I can confirm that the changes fix the issue.

All 28 comments

Hi @esduran, thanks for reporting this issue!
I cannot repro it on my machine, can you make sure your vcpkg is latest?
image

Thanks.

Hi @JackBoosY, I did a complete purge of vcpkg and reinstalled the packages I listed above. I still get the same exception thrown in Visual Studio of Exception thrown: read access violation. g was nullptr. for the file _imgui.cpp_ in the function ImGui::Begin line 5400.

I am also getting the same error when using ImGui for SFML using vcpkg.

Screenshot (11)
Screenshot (10)

Any idea if it gets fixed if both of them are installed manually?

@BryanTriana I ended up statically building SFML from source and then building ImGUI-SFML from source as well. That has been working with zero issues thus far.

Also getting the same issue - I will try the static building of SFML like @esduran has done.

I'm digging deeper into this issue, which may be caused by the fact that the symbols are not reused.

Assertion failed: g.FrameScopeActive && "Forgot to call ImGui::NewFrame()?", file C:\vcpkg\buildtrees\imgui\src\v1.73-a85d24b4b8\imgui.cpp, line 4161 Assertion failed: ImGui::GetCurrentContext() != 0 && "Missing dear imgui context. Refer to examples app!", file C:\vcpkg\buildtrees\imgui\src\v1.73-a85d24b4b8\imgui_demo.cpp, line 197

imgui-sfml
code : https://github.com/eliasdaler/imgui-sfml/blob/master/examples/main.cpp

I am having the same issue, I will try to resort to manual build...

I also have the same problem. Here's my hypothesis.

ImGui::SFML::Init(window) calls ImGui::CreateContext(), which initializes a global pointer GImGui. Since this is in the namespace ImGui::SFML and vcpkg builds it as a dynamic library, it means ImGui::SFML has its own global GImGui. Now, when calling ImGui::Begin(), GImGui is accessed, but since it is in the ImGui namespace, it is a different global pointer, which hasn't been initialized. Ah, evil global variables... That is why static linking works: there is then a single global pointer.

I hacked something in the debugger that seemed to work. In the main, I added a call to ImGui::SetCurrentContext(ctx), where ctx is actually the value of GImGui in the ImGui::SFML scope, and it works (until I find there is another global variable in ImGui...).

Problem is: I don't find a way to get the ImGui::SFML pointer cleanly. I think a method should be added to ImGui::SFML to get the current context pointer. Or maybe it would be simpler to always static link ImGui::SFML (can vcpkg do that?).

Hi Vincent,

For the time being the workaround for me is the manual integration described here:
https://eliasdaler.github.io/using-imgui-with-sfml-pt1/

We are digging the cause of this issue and try to support imgui-sfml to generate dynamic libraries.

It seems that there are many issues with the imgui library, and we want to fix this. Does anyone have an example that reproduces this issue? We aren't able to reproduce this issue on our machines.

I did almost the same thing as the OP. To reproduce, with VS2019 and vcpkg integration enabled:

  • vcpkg install imgui-sfml (x64)
  • create empty project in VS2019
  • add new C++ source file with the following code (imgui-sfml hello world)
  • compile and run in x64 Debug
#include "imgui.h"
#include "imgui-SFML.h"

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

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    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("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}

This will assert on the call to ImGui::Begin.

  • vcpkg install imgui sfml
  • x86 or x64
  • current visual studio updated 3/30/2020

image

Assertion failed: ImGui::GetCurrentContext() != 0 && "Missing dear imgui context. Refer to examples app!", file C:\vcpkg\buildtrees\imgui\src\v1.73-a85d24b4b8\imgui_demo.cpp, line 197

197
IM_ASSERT(ImGui::GetCurrentContext() != NULL && "Missing dear imgui context. Refer to examples app!"); // Exceptionally add an extra assert here for people confused with initial dear imgui setup

code

#include "imgui.h"
#include "imgui-SFML.h"

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

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    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::ShowTestWindow();

        ImGui::Begin("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();

    return 0;
}

Attempt 2 :
image

image

image

image

code

#include "imgui.h"
#include "imgui-SFML.h"

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

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    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("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}

We will set imgui-sfml to only static library.

Hi guys, I'm fixing this issue in #10840, can anyone help me to test it?

Thanks.

I’m happy to help. What do you need me to do? Not just a git pull against my vcpkg install... I will have to make sure I have got rid of all static builds of SFML on my machine first.

@luketrevorrow Use my changes and rebuild imgui-sfml would be okay.

Hi all,

Do you still need testing?

Happy to help,
Nico

On Thu, 16 Apr 2020, 04:06 Jack·Boos·Yu, notifications@github.com wrote:

@luketrevorrow https://github.com/luketrevorrow Use my changes and
rebuild imgui-sfml would be okay.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vcpkg/issues/9660#issuecomment-614389326,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEUH4TICQE2SNNUCJEFYPOTRMZY2BANCNFSM4KGCZR5Q
.

Is not working for me but i also made a big mistake, turns out sfml-imgui has no support for the current sfml and it seems is not going to work for any version higher than 2.1 sfml

if im wrong about it please tell me, is not working for me and thats the only reason i can think of

@NikBomb Yes please.

@WeskerPower Could you provide me more details?

Thanks.

x86 - debug, win10, visual studio 2019

Well im using it without Cmake, according to umgui-sfml all i need to do is copy paste this code, after i install imgui-sfml with vcpkg

#include "imgui.h"
#include "imgui-SFML.h"

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

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    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("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}

then i have different issues one i notice a few days ago was that is not loading some files

'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\Imgui.exe'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. 
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\sfml-system-d-2.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\ImGui-SFML.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\sfml-graphics-d-2.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\sfml-window-d-2.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\opengl32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\opengl32.dll'. 
'Imgui.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\opengl32.dll'
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. 
'Imgui.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\winmmbase.dll'
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\DXCore.dll'. 
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\freetyped.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\zlibd1.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\bz2d.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'E:\Gits\Imgui\Imgui\Debug\libpng16d.dll'. Symbols loaded.
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_830a0263f2ee97ce\nvoglv32.dll'. 
'Imgui.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_830a0263f2ee97ce\nvoglv32.dll'
'Imgui.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_830a0263f2ee97ce\nvoglv32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\umpdc.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptsp.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcrypt.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wtsapi32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntmarta.dll'. 
The thread 0x3aa4 has exited with code 0 (0x0).
The thread 0x3884 has exited with code 0 (0x0).
The thread 0x36d4 has exited with code 0 (0x0).
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvspcap.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winsta.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dinput8.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\InputHost.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\CoreMessaging.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\CoreUIComponents.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WinTypes.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\propsys.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\hid.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\TextInputFramework.dll'. 
'Imgui.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. 
Exception thrown: read access violation.
**g** was nullptr.

The program '[6028] Imgui.exe' has exited with code 0 (0x0).
Severity    Code    Description Project File    Line    Suppression State   Detail Description
Warning C6011   Dereferencing NULL pointer 'Buf.Data'.  Imgui   C:\vcpkg\installed\x86-windows\include\imgui.h  1639    

Imgui.exe!ImGui::Begin(const char * name, bool * p_open, int flags) Line 5248   C++

Imgui.exe!main() Line 31    C++



  | Name | Value | Type
-- | -- | -- | --
â–¶ | *GImGui | <struct at NULL> | ImGuiContext


  | Name | Value | Type
-- | -- | -- | --
â–¶ | g | <struct at NULL> | ImGuiContext &

Im not sure if im doing something wrong over here

@WeskerPower Did you use #10840 changes?

@WeskerPower Did you use #10840 changes?

i just replace or created those files and didnt work for me, should i do anything else ?

image

@WeskerPower You should clone my repo https://github.com/JackBoosY/vcpkg.git and switch to branch dev/jack/9660.

`

@WeskerPower You should clone my repo https://github.com/JackBoosY/vcpkg.git and switch to branch dev/jack/9660.

Thanks ok i had a bit of trouble there, but i manage to do what i needed to do, and now its working

image

i can confirm that solves the issue of g been null

Dear All, I can confirm that the changes fix the issue.

Fixed by #11800.

Was this page helpful?
0 / 5 - 0 ratings