mCodingLLC / VideosSampleCode

Code from the mCoding sample videos
MIT License
978 stars 203 forks source link

issue with running pyimgui demo.py #8

Closed gskluzacek closed 2 years ago

gskluzacek commented 2 years ago

Hi James,

After activating my virtualenv and runnIng demo.py (which I downloaded from your git hub repo), I got the following error: ImportError: ('Unable to load OpenGL library', 'dlopen(OpenGL, 10): image not found', 'OpenGL', None)

Which I was able to fix by following the directions here basically, by modifying ctypesloader.py file in my virtualenv's lib/python3.6/site-packages/OpenGl/platform directory

and changing this: fullName = util.find_library( name )

to this: fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'

Then at least I was able to get demo.py to launch and the main window came up.

Though I did notice that the first window Hello, Imgui! opened right on top of the Active Examples window, and slightly too small... all the other windows also open right on top of the other windows that were already displayed. Not sure if that's an issue but, from the video it didn't look demo.py behaved that way when you ran it. Though I did notice that a imgue.ini file did appear that seems to manage the window sizes and locations...

That minor issue aside, when I try the menu bar example window, it shows fine, but when I click the close menu item on that window's file menu, the program crashes & I get the following error.

(imgui_37) Gregs-5k-iMac-Octo-Core-2:imgui gskluzacek$ python demo.py 
exception caught, but too late!
Traceback (most recent call last):
  File "demo.py", line 296, in <module>
    main()
  File "demo.py", line 289, in main
    render_frame(impl, window, jb)
  File "demo.py", line 249, in render_frame
    imgui.render()
  File "imgui/core.pyx", line 1891, in imgui.core.render
imgui.core.ImGuiError: ImGui assertion error (g.CurrentWindowStack.Size == 1) at imgui-cpp/imgui.cpp:3476

The one other issue I'm seeing is that when I try to open the last four example windows: tab bar, list box, popup context void and table, the program crashes with errors similar to the following:

(imgui_37) Gregs-5k-iMac-Octo-Core-2:imgui gskluzacek$ python demo.py 
Traceback (most recent call last):
  File "demo.py", line 296, in <module>
    main()
  File "demo.py", line 289, in main
    render_frame(impl, window, jb)
  File "demo.py", line 245, in render_frame
    frame_commands()
  File "demo.py", line 180, in frame_commands
    if imgui.begin_tab_bar("MyTabBar"):
AttributeError: module 'imgui' has no attribute 'begin_tab_bar'

The attribute name mentioned in the error messages and the line number specified varies. For example: for the list box example, the attribute named in the error is begin_list_box and the line number is 197 instead of 189 as shown above.

Additionally, the simple Basic GUI drawing loop code given on the pyimgui read the docs site does not bring up the window as shown there. The program just runs and exists without any thing being displayed and no error messages.

I'm rather suspect at this point, since the original error that occurred with openGL.

Do you think its my installation, OS, ??? Do you have any suggestions that you think I should try?

Here is the code from the pyimgui read the docs site:

import imgui

# initilize imgui context (see documentation)
imgui.create_context()
imgui.get_io().display_size = 100, 100
imgui.get_io().fonts.get_tex_data_as_rgba32()

# start new frame context
imgui.new_frame()

# open new window context
imgui.begin("Your first window!", True)

# draw text label inside of current window
imgui.text("Hello world!")

# close current window context
imgui.end()

# pass all drawing comands to the rendering pipeline
# and close frame context
imgui.render()
imgui.end_frame()

Here's a screen shot of the example windows that I am able to open image


By the way, I really love the content that you put out on your Youtube channel. I think what you contribute to the community is just fantastic. Keep up the good work.

Regards, Greg Skluzacek

mCodingLLC commented 2 years ago

The OpenGL thing is a known error with some Macs (not sure if this is an M1 thing or a laptop thing or a GPU thing), which I've heard requires a workaround like what you found, so it's not just you. The crash in the menu bar example is exactly what my PR is supposed to fix. Even though the exception is caught, the imgui stack is corrupted and the program will crash anyway. To fix this you would have to use my PR (not yet accepted) and the with statement shown in demo-newstyle.py. The rest of the issues stem from the fact that when you pip install you get the latest published version, not the dev version. As such the things in the delta from the current release to the dev branch will crash. To try the dev branch or my PR you would have to git clone and checkout your desired commit, then pip install -e . -v (or replace . with the location where you cloned).

gskluzacek commented 2 years ago

Thanks for the quick followup and the reassurance that it not just me with regards to the errors from the demo.py script.

For some reason, I was under the assumption that the demo.py script only contained code that was from BEFORE your pull request and that the demo-newstyle.py script was the code AFTER your pull request.

Though its not your problem, any idea why happens when I try to run the Basic GUI drawing loop code given on the pyimgui read the docs site ?

mCodingLLC commented 2 years ago

Yes that is correct, demo.py contains code that was from before my PR, and demo-newstyle.py contains code after the PR. But remember here that the before is still on the dev branch, which is not what you get when you pip install.

             latest release (what you get when you pip install)
            /
--------------------master
                \----------------------------------dev
                                                    \-my PR

As for why the Basic GUI drawing loop code doesn't work it is because the documentation is just not clear about what that snippet is supposed to do (docs can always be improved! submit your own PR!). It does not actually draw the window and it doesn't even contain a loop. They attempt to explain this:

Of course this is not enough to create fully working GUI application with pyimgui. The bare imgui.core module is not able to render anything on its own. The imgui.render() function just passes abstract ImGui drawing commands to your rendering backend. In order to make it work you will first have to initialize the rendering backend of your choice.

Actual minimal examples are much closer to what is found in my demo.py and the official examples can be found here: https://github.com/pyimgui/pyimgui/tree/master/doc/examples The integrations_glfw3 would be the most similar to what I was doing, but if OpenGL is not well-supported on your Mac, you may want to try a different backend such as sdl2.

gskluzacek commented 2 years ago

Thanks for the clarification....

Ya, I read that in the documentation as well.. but saw the "allegedly" displayed window as an image in the docs right below the sample code. So I was confused, to say the least, but thought: now why would the show a screenshot if the example code didn't produce anything!! LOL

image

Thanks for your help.