SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Adding SDL2 causes immediate crash with error or stack

Open BigBallard opened this issue 1 year ago • 1 comments

I just added SDL2 via CMake and am experiancing unknown behavior. After adding SDL to my library and only including the SDL2/SDL.h file, my program immediately crashes with no error.

Steps Taken:

Download SDL2-devel-2.28.5-mingw.zip from release-2.28.5 and unpack to contents to <project_root>/deps/SDL2.

Added the following to my CMakeLists.txt:

set(SDL2_DIR "deps/SDL2/cmake")
find_package(SDL2 REQUIRED) 
... 
include_directories(mylib )
{SDL2_INCLUDE_DIRS}) 
target_link_libraries(mylib PUBLIC 
SDL2::SDL2main SDL2::SDL2) 

Build project, results successful.

Include the SDL/SDL2.h header in my source code somewhere without any SDL2 specific code (eg SDL_Init)

Run the program, get Process finished with exit code -1073741515 (0xC0000135).

There is no error/stack trace to explain what is going on. I can only assume it is either a result of my cmake configuration or there is something going on the SDL2 that I don’t understand.

Any assistance would be greatly appreciated.

BigBallard avatar Jan 17 '24 20:01 BigBallard

Have you copied SDL2.dll to the same directory as your executable? Or have you configured your PATH environment variable to include the path of SDL2.dll?

The following CMake code copies SDL2.dll in a post-build event.

if(WIN32)
  add_custom_command(TARGET yourexe POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:yourexe>"
  )
endif()

(or you can do the copy manually)

madebr avatar Jan 17 '24 21:01 madebr