i2d-imgui icon indicating copy to clipboard operation
i2d-imgui copied to clipboard

The example crashes on Linux with -11 error code

Open GrimMaple opened this issue 4 years ago • 13 comments

I have been trying to get the example to work on Linux for a few days now, and I'm genuinely stuck. Every time I run the example, I get acces violation at ImGui_ImplSDL2_InitForOpenGL(window, gl_context);. This only happens on my Linux laptop, on Windows the example runs perfectly.

I have tried SDL backend examlpe of cimgui itself, and it works smoothly, which leads me to believe the problem is in bindbc-imgui.

I have used deps/CMakeLists.txt to build necessary libraries, and I copied them to /usr/lib.

Does anyone know what could be causing the issue, or where I should look for additional info? The errors function of bindbc-loader returns nothing.

GrimMaple avatar Dec 29 '21 13:12 GrimMaple

I feel like this might be related to #8, I'll take a look, it might take a bit.

playmer avatar Dec 29 '21 17:12 playmer

It is not entirely related. This issue can be fixed by building cimgui with a modified build script. Basically our current build setup fails spectacularly on making a functional build on Linux. Solution is to build stuff yourself and set the parameters in the cmake config file of cimgui yourself + change some config stuff in SDL2 so that it can build properly.

Ideally we want to track down the shortcommings of our build script so that it works on Linux too and builds using Linux sensibilities (not compiling SDL2, etc. from source)

LunaTheFoxgirl avatar Dec 29 '21 20:12 LunaTheFoxgirl

Solution is to build stuff yourself and set the parameters in the cmake config file of cimgui yourself + change some config stuff in SDL2 so that it can build properly. Care to give the custom build script, or at least instructions on how it could be built?

GrimMaple avatar Dec 29 '21 21:12 GrimMaple

The modified build script I wrote for cimgui's CMakeLists.txt

cmake_minimum_required(VERSION 3.1)

project(cimgui)

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_tables.cpp)
	set(TABLES_SOURCE "imgui/imgui_tables.cpp")
else()
	set(TABLES_SOURCE "")
endif()


#general settings
file(GLOB IMGUI_SOURCES
    cimgui.cpp
    imgui/imgui.cpp
    imgui/imgui.h
    imgui/imgui_draw.cpp
    imgui/imgui_demo.cpp
    imgui/imgui_internal.h
    imgui/imgui_widgets.cpp
	${TABLES_SOURCE}
)

set(IMGUI_STATIC "no" CACHE STRING "Build as a static library")
set(IMGUI_FREETYPE "yes" CACHE STRING "Build with freetype library")
set(IMGUI_FREETYPE_IN_TREE "no" CACHE STRING "freetype library is being build in-tree")
set(IMGUI_LIBRARIES )

if(IMGUI_FREETYPE)
    if (NOT IMGUI_FREETYPE_IN_TREE)
       #FIND_PACKAGE(freetype REQUIRED PATHS ${FREETYPE_PATH})
       FIND_PACKAGE(Freetype REQUIRED)
    endif ()

    list(APPEND IMGUI_LIBRARIES Freetype::Freetype)
    list(APPEND IMGUI_SOURCES imgui/misc/freetype/imgui_freetype.cpp)
    add_definitions("-DCIMGUI_FREETYPE=1")
    add_definitions("-DIMGUI_ENABLE_FREETYPE=1")
    add_definitions("-DIMGUI_ENABLE_STB_TRUETYPE=1")
endif(IMGUI_FREETYPE)

#add library and link
if (IMGUI_STATIC)
    add_library(cimgui STATIC ${IMGUI_SOURCES})
else (IMGUI_STATIC)
    add_library(cimgui SHARED ${IMGUI_SOURCES})
endif (IMGUI_STATIC)

target_compile_definitions(cimgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1)
if (WIN32)
    target_compile_definitions(cimgui PUBLIC IMGUI_IMPL_API=extern\t\"C\"\t__declspec\(dllexport\))
    list(APPEND IMGUI_LIBRARIES imm32)
else (WIN32)
    target_compile_definitions(cimgui PUBLIC IMGUI_IMPL_API=extern\t\"C\"\t)
endif (WIN32)

set(IMGUI_SDL_IN_TREE "no" CACHE STRING "SDL library is being build in-tree")
set(IMGUI_SDL "yes" CACHE STRING "Build with SDL")
set(IMGUI_OPENGL2 "no" CACHE STRING "Build with OpenGL2")
set(IMGUI_OPENGL3 "yes" CACHE STRING "Build with OpenGL3")

if (IMGUI_SDL)
    if (NOT IMGUI_SDL_IN_TREE)
        FIND_PACKAGE(SDL2 REQUIRED PATHS ${SDL2_PATH})
    endif ()

    target_sources(cimgui
    PRIVATE
        imgui/backends/imgui_impl_sdl.cpp
        imgui/backends/imgui_impl_sdl.h
    )

    target_link_libraries(cimgui PRIVATE SDL2::SDL2)
endif()

if (IMGUI_OPENGL2)
    target_sources(cimgui
    PRIVATE
        imgui/backends/imgui_impl_opengl2.cpp
        imgui/backends/imgui_impl_opengl2.h
    )

    if (UNIX)
        target_link_libraries(cimgui PRIVATE GL)
    endif()
endif()

if (IMGUI_OPENGL3)
    target_sources(cimgui
    PRIVATE
        imgui/backends/imgui_impl_opengl3.cpp
        imgui/backends/imgui_impl_opengl3.h
	imgui/backends/imgui_impl_opengl3_loader.h
    )

    if (UNIX)
        target_link_libraries(cimgui PRIVATE GL)
    endif()
endif()

target_include_directories(cimgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(cimgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
set_target_properties(cimgui PROPERTIES PREFIX "")
target_link_libraries(cimgui PUBLIC ${IMGUI_LIBRARIES})

#install
install(TARGETS cimgui
    RUNTIME DESTINATION  .
    LIBRARY DESTINATION  .
    ARCHIVE DESTINATION  .
)

#test
set(CIMGUI_TEST "no" CACHE STRING "Enable compilation of a test unit based on imgui null")

if (CIMGUI_TEST)
  add_subdirectory(test)
endif ()

As for SDL2 you have to comment out a section in its CMakeLists.txt file that handles not building in its source directory (for some reason all directories counts as the source directory for me)

LunaTheFoxgirl avatar Dec 29 '21 21:12 LunaTheFoxgirl

I guess there was something terribly wrong with my setup, because I did something and it works now. The problem is, I haven't quite managed to understand what exactly it was that I did and it helped. I didn't even use suggested modified build script.

GrimMaple avatar Jan 01 '22 15:01 GrimMaple

I have ran the example on a fresh install in a VM, getting error -11 again. It seems that something on my system actually fixes this instead of breaking. bindbc.loader returns no errors on a call to errors. I will try to investigate when I have some more free time.

GrimMaple avatar Jan 12 '22 15:01 GrimMaple

I have ran the example on a fresh install in a VM, getting error -11 again. It seems that something on my system actually fixes this instead of breaking. bindbc.loader returns no errors on a call to errors. I will try to investigate when I have some more free time.

any updates? trying to get this running on linux myself, heh. it's totally fine if you haven't found anything, just curious.

zaydlang avatar Feb 02 '22 21:02 zaydlang

I have ran the example on a fresh install in a VM, getting error -11 again. It seems that something on my system actually fixes this instead of breaking. bindbc.loader returns no errors on a call to errors. I will try to investigate when I have some more free time.

any updates? trying to get this running on linux myself, heh. it's totally fine if you haven't found anything, just curious.

The build script I posted should make cimgui.so build. It's not pretty though. I have been investigating the root problem and I might give a shot fixing the build script over the weekend to work properly on Linux (as well as arm64 and macOS)

LunaTheFoxgirl avatar Feb 03 '22 07:02 LunaTheFoxgirl

I have ran the example on a fresh install in a VM, getting error -11 again. It seems that something on my system actually fixes this instead of breaking. bindbc.loader returns no errors on a call to errors. I will try to investigate when I have some more free time.

any updates? trying to get this running on linux myself, heh. it's totally fine if you haven't found anything, just curious.

I have built cimgui and SDL2 from scratch myself, and that seems to be fixing everything. Though the correct combination of building yourself and building from this binding is still a mystery to me

GrimMaple avatar Feb 04 '22 10:02 GrimMaple

How do I use that CMakeLists.txt? Tried to build cimgui with it and I just get:

-- Configuring done
CMake Error at CMakeLists.txt:46 (add_library):
  Cannot find source file:

    imgui/backends/imgui_impl_sdl.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at CMakeLists.txt:46 (add_library):
  Target "cimgui" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?

TheGag96 avatar Feb 05 '22 01:02 TheGag96

Do you maybe not have the submodules cloned? There's several submodules in the deps directory.

playmer avatar Feb 05 '22 01:02 playmer

No, they're cloned. my command was, inside a build dir:

cmake ..

TheGag96 avatar Feb 05 '22 22:02 TheGag96

Issue is either that some distros call the SDL2 package SDL2 and some call it SDL2::SDL2 or you don't have SDL2 + it's development libraries on-system

The build script I provided tries to use the system installed libraries instead of the cloned versions

LunaTheFoxgirl avatar Feb 10 '22 16:02 LunaTheFoxgirl