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

RunTimeError:RuntimeError: IM_ASSERT( g.CurrentDpiScale > 0.0f && g.CurrentDpiScale < 99.0f ) #293

Closed
suitmyself opened this issue Dec 10, 2024 · 9 comments

Comments

@suitmyself
Copy link

suitmyself commented Dec 10, 2024

Describe the issue

pip install imgui-bundle
demo_imgui_bundle

report error:
image

python version 3.10.15

@pthom
Copy link
Owner

pthom commented Dec 10, 2024

@pthom
Copy link
Owner

pthom commented Dec 11, 2024

You may try to set

[DpiAwareParams]
dpiWindowSizeFactor=1
;fontRenderingScale=1

in a hello_imgui.ini as mentioned here

Does that help?

@suitmyself
Copy link
Author

I just compile from source, and algo get this error.
then I comment this assert, everything becomes ok.
even I uncomment this assert back, it no longer report errrr.
I this .ini file has been fixed after a success running.

but I think this error should be fix at the beginning.

@FaceCrap
Copy link

FaceCrap commented Dec 18, 2024

I'd like to re-open this one.
I'm running into the same issue and despite downloading the suggested hello_imgui.ini and uncommenting those settings in the same folder as demo_imgui_bundle.py, heck I even copied it to all parent folders, it keeps throwing the IM_ASSERT error.

I only got it to work partially by first commenting the call to demo_function() and running the demo, this created an empty window with a non-functional menu bar in top. But the menu bar and status bar looked like I had DPI scaling set to 200%.

After uncommenting the call demo_function() it started running supposedly as intended, but it was still unusable as the top of the window was located offscreen (negative Y coord on a 3440x1440 screen.) and there was no system menu to make it move down.

Removing every copy of hello_imgui.ini I previously created and repeating the steps above finally led to a usable demo and this time even with normal DPI scaling (100%) and it had a system menu..

However, instead of a hello_imgui.ini there now exists a Dear_ImGui_Bundle_interactive_manual.ini in the imgui_bundle folder...

@pthom
Copy link
Owner

pthom commented Dec 18, 2024

IM_ASSERT( g.CurrentDpiScale > 0.0f && g.CurrentDpiScale < 99.0f )

I cannot reproduce the issue on my side, which makes it difficult to diagnose. Please provide more information about your settings:

  • OS
  • Number of monitors
  • Resolution and scaling

Analysis: this assert is thrown deep inside ImGui:

imgui.cpp

void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* viewport)
{ ...
    g.CurrentDpiScale = viewport ? viewport->DpiScale : 1.0f;
    g.CurrentViewport = viewport;
    IM_ASSERT(g.CurrentDpiScale > 0.0f && g.CurrentDpiScale < 99.0f); // Typical correct values would be between 1.0f and 4.0f
...
}

As a consequence, viewport->DpiScale is likely incorrect. Could you add a log to display its value?

According to my search, the only place where viewport->DpiScale is set is here:

imgui.cpp

ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& pos, const ImVec2& size, ImGuiViewportFlags flags)
{
...
// This is where ImGui uses its own platform system to set the DpiScale. Could you add some log here?
        if (viewport->PlatformMonitor != -1)
            viewport->DpiScale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
...
}

Things to try:

demo_imgui_bundle.py: try to skip the first frames

def show_module_demo(demo_filename: str, demo_function: Callable[[], None]) -> None:
    if imgui.get_frame_count() < 3:
        return
    if imgui.collapsing_header("Code for this demo"):
        demo_utils.show_python_vs_cpp_file(demo_filename)
    demo_function()

After uncommenting the call demo_function() it started running supposedly as intended, but it was still unusable as the top of the window was located offscreen (negative Y coord on a 3440x1440 screen.) and there was no system menu to make it move down.

You can reduce the size of the window using the bottom right corner, it will then be repositioned.
Anyhow, this was fixed by f7e1dc4

@FaceCrap
Copy link

FaceCrap commented Dec 18, 2024

My setup is
Windows 10 Pro 22H2 19045.5247
Dual Monitors
Primary: 3440x1440 @ 100% DPI
Secondary: 1920x1080 @ 100% DPI

Skipping the first frame was already enough to make it work.

def show_module_demo(demo_filename: str, demo_function: Callable[[], None]) -> None:
    if imgui.get_frame_count() < 2:  # <= this alone already fixed it
        return
    if imgui.collapsing_header("Code for this demo"):
        demo_utils.show_python_vs_cpp_file(demo_filename)
    demo_function()

After having been able to run the demo, I could not reproduce the odd DPI scaling issue.

As for:

As a consequence, viewport->DpiScale is likely incorrect. Could you add a log to display its value?

According to my search, the only place where viewport->DpiScale is set is here:

imgui.cpp

ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& pos, const ImVec2& size, ImGuiViewportFlags flags)
{
...
// This is where ImGui uses its own platform system to set the DpiScale. Could you add some log here?
        if (viewport->PlatformMonitor != -1)
            viewport->DpiScale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
...
}

I would gladly insert logging here, but I'm running it from VSCode using a Python 3.11.2 .venv, and I have zero C++ knowledge, so wouldn't know how to insert logging here, plus I don't think it would get executed as it will need to be recompiled?.

Also, there seems to be two instances of this def.
Once in external\hello_imgui\external\imgui\imgui.cpp
and in external\imgui\imgui\imgui.cpp

On the off chance I added this line just before the if check in both copies;

IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Viewport->PlatformMonitor = '%s'\n", viewport->PlatformMonitor);

Guessing from a line slightly higher up this would be the correct syntax, but as I expected I didn't see any output in VSCode's debug console.

Thinking doing pip install -v . again might recompile these files, but like the first time I am getting an error. Doesn't look like it's fatal as the demo ran fine once I passed the initial hurdle. Below the output from that command.

pip_install_-v_{current-folder}_log.txt

@FaceCrap
Copy link

Oddly enough, when running each of the demo's individually, there is no issue at all.
It only occurs when running the demo container demo_imgui_bundle.py

pthom added a commit that referenced this issue Dec 18, 2024
@pthom
Copy link
Owner

pthom commented Dec 18, 2024

Hum, this issue will be difficult to track.
Since it seems to be limited to demo_imgui_bundle.py, I pushed a patch with a symptomatic correction, see this commit

@pthom
Copy link
Owner

pthom commented Dec 18, 2024

New wheels will be available at https://github.com/pthom/imgui_bundle/actions/runs/12398172321

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

3 participants