Build imgui-bundle example successfully into excutable, but crashed at getting windows WndProc hook
Nuitka Version
2.1.5
Commercial: None
Python: 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:40:50) [MSC v.1937 64 bit (AMD64)]
Flavor: Anaconda Python
Executable: C:\Users\ABC\AppData\Local\Programs\miniconda3\envs\test\python.exe
OS: Windows
Arch: x86_64
WindowsRelease: 10
Version C compiler: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64\cl.exe (cl 14.3).I am able to run the example imgui_example_glfw_opengl3.py from imgui_bundle package without issue by executing:
python imgui_example_glfw_opengl3.pyBut when I was trying to build the example imgui_example_glfw_opengl3.py into an executable app using Nuitka. Below are my conda env packages:
Package Version
------------------------- -----------
Nuitka 2.1.5
PyOpenGL 3.1.7
glfw 2.7.0
imgui-bundle 1.3.0
...
(and other packages come after running: pip install imgui-bundle)With commands:
nuitka imgui_example_glfw_opengl3.py --standalone --follow-imports --python-flag=-O --python-flag=-v --output-dir=distNuitka produced an executable successfully, but when I run it, it stopped at following debug message:
(... lots of message ...)
import glfw_preview # denied responsibility
import cffi # considering responsibility (find_spec)
import cffi # denied responsibility
Loaded glfw
import 'glfw' # <class 'nuitka_module_loader'>
Loaded imgui_bundle.glfw_utils
import 'imgui_bundle.glfw_utils' # <class 'nuitka_module_loader'>
Loaded imgui_bundle
import 'imgui_bundle' # <class 'nuitka_module_loader'>
Traceback (most recent call last):
File "C:\Users\ABC\source\imgui_sample\dist\imgui_opengl.dist\imgui_example_glfw_opengl3.py", line 289, in <module>
File "C:\Users\ABC\source\imgui_sample\dist\imgui_opengl.dist\imgui_example_glfw_opengl3.py", line 102, in main
RuntimeError: IM_ASSERT( bd->PrevWndProc != nullptr ) --- imgui_impl_glfw.cpp:651
# clear builtins._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
(... lots of message ...)Trace to the source, the message comes from the following:
# You need to transfer the window address to imgui.backends.glfw_init_for_opengl
# proceed as shown below to get it.
window_address = ctypes.cast(window, ctypes.c_void_p).value <---- getting glfw window address
imgui.backends.glfw_init_for_opengl(window_address, True) <---- Executable stopped hereWhich is caused by getting null pointer at line 651 from imgui_impl_glfw.cpp:
649 #ifdef _WIN32
650 bd->PrevWndProc = (WNDPROC)::GetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC);
651 IM_ASSERT(bd->PrevWndProc != nullptr); <--------------------- Null pointer here
652 ::SetWindowLongPtrW((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc);
#endifIn summary, my issue is that directly running python script has no issue. The executable is generated successfully by Nuitka without error. But crashed due to null WndProc at the source described above.
My guess is could it be the way Nuitka handles ctypes.c_void_p caused the issue?
Thanks for the help!
Source: Nuitka/Nuitka