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

"Invalid DisplaySize value" assertion failed via glew and gl3w #79

Closed
haxpor opened this Issue Oct 29, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@haxpor
Copy link

haxpor commented Oct 29, 2018

I tested with SDL2 (2.0.9 9bb50edccc46) on macOS 10.14 (18A391) and ported imgui_impl_opengl3.h, imgui_impl_opengl3.cpp, and main.cpp to C (checked calling to cimgui properly).

I faced with the problem of

Assertion failed: (g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value"), function NewFrame, file imgui/imgui.cpp, line 3090.
Abort trap: 6

Download the project: cimgui-sdl2.tar.gz.

To build, simply ...

  • make to build against gl3w
  • make glew to build against glew

ps.

  • notice that I have to do relative-path symlink cimgui.dylib as libcimgui.dylib, related to #78 .
  • X11 is installed at /opt/X11 and its include directory is added in Makefile as well.
@sonoro1234

This comment has been minimized.

Copy link
Contributor

sonoro1234 commented Oct 30, 2018

I cant compile as I am on windows
It is a imgui issue (not cimgui)
I searched in imgui and got only this ocornut/imgui#1562
something must be wrong in your edited files?
In my cimgui usage from LuaJIT I use
https://github.com/ocornut/imgui/blob/master/examples/imgui_impl_opengl3.cpp for compiling dll
and then
https://github.com/cimgui/cimgui/blob/master/generator/output/cimgui_impl.h as header to use it from C
This way you get for free in cimgui the work done in implementations by ocornut
Only main.c should be rewritten!!

@sonoro1234

This comment has been minimized.

Copy link
Contributor

sonoro1234 commented Oct 30, 2018

ImVec2 vec;
    vec.x = (float)w;
    vec.y = (float)h;
    io.DisplaySize = vec;

    vec.x = w > 0 ? ((float)display_w / w) : 0;
    vec.y = h > 0 ? ((float)display_h / h) : 0;
    io.DisplayFramebufferScale = vec;

This could be wrong
In C io.DisplaySize = vec; is not a copy constructor so I think you get the same on both DisplaySize and DisplayFramebufferScale
io.DisplaySize.x = (float)w; and so on could do the trick but as told you: Try to only rewrite main.c

@sonoro1234

This comment has been minimized.

Copy link
Contributor

sonoro1234 commented Oct 30, 2018

Also in

ImGuiIO io = *igGetIO();
io.DisplaySize = vec;

you are not modifying original ImGuiIO
perhaps

ImGuiIO *io = igGetIO();
io->DisplaySize = vec;
or
io->DisplaySize.x = (float)w;

Main recomendation: Try to only rewrite main.c

@haxpor

This comment has been minimized.

Copy link

haxpor commented Oct 30, 2018

Thank you so much for your time checking this out!
You shed the light for me as I overlook that in fact I can keep SDL's implementation for imgui code intact, and compile then into object files or library then link it to our main C source.

I made it work regarding to your suggestion to not modify anything.
To keep this as a record, there are 3 things I need to do to make it works

  1. I have to slightly modify imgui_impl_sdl.h and imgui_impl_sdl.cpp to put struct in front of SDL_Wnidow in function declaration.
  2. Add -DIMGUI_IMPL_API="extern \"C\"" for compile flags when compile both of imgui_impl_sdl and imgui_impl_opengl3. To make it provide C interface to work with C source code.
  3. In linking to our main source code, I need to also add -lc++ so it won't shout out undefined symbols.

I attached working test project: cimgui-sdl2.tar.gz or on github sdl2-cimgui-demo
(same make command for either gl3w or glew).

Thanks for the help and cimgui. It all works fine now.

@haxpor haxpor closed this Oct 30, 2018

@sonoro1234

This comment has been minimized.

Copy link
Contributor

sonoro1234 commented Oct 30, 2018

I am C++ compiling this in
https://github.com/sonoro1234/LuaJIT-ImGui/blob/master_auto_implementations/CMakeLists.txt
without any file modification, only IMGUI_IMPL_API definition

Then to use it from C the header should be https://github.com/cimgui/cimgui/blob/master/generator/output/cimgui_impl.h

@haxpor

This comment has been minimized.

Copy link

haxpor commented Oct 30, 2018

Thanks! Looking at them, it's clear to me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment