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

The example crashes on Linux with -11 error code #13

Open
GrimMaple opened this issue Dec 29, 2021 · 13 comments
Open

The example crashes on Linux with -11 error code #13

GrimMaple opened this issue Dec 29, 2021 · 13 comments

Comments

@GrimMaple
Copy link

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.

@playmer
Copy link
Collaborator

playmer commented Dec 29, 2021

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

@LunaTheFoxgirl
Copy link
Member

LunaTheFoxgirl commented Dec 29, 2021

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)

@GrimMaple
Copy link
Author

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?

@LunaTheFoxgirl
Copy link
Member

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)

@GrimMaple
Copy link
Author

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
Copy link
Author

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.

@zaydlang
Copy link

zaydlang commented Feb 2, 2022

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.

@LunaTheFoxgirl
Copy link
Member

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)

@GrimMaple
Copy link
Author

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

@TheGag96
Copy link

TheGag96 commented Feb 5, 2022

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?

@playmer
Copy link
Collaborator

playmer commented Feb 5, 2022

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

@TheGag96
Copy link

TheGag96 commented Feb 5, 2022

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

cmake ..

@LunaTheFoxgirl
Copy link
Member

LunaTheFoxgirl commented Feb 10, 2022

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

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

5 participants