Created
August 1, 2026 10:23
-
-
Save edg-l/f675f2a01fbb4b6a1afb0906ad05d64c to your computer and use it in GitHub Desktop.
ddnet PR #12467: fix map_render GLEW/CI build + InitError==-2 shutdown crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/CMakeLists.txt b/CMakeLists.txt | |
| index da16f4905..a509c9961 100644 | |
| --- a/CMakeLists.txt | |
| +++ b/CMakeLists.txt | |
| @@ -3190,7 +3190,7 @@ if(TOOLS) | |
| endif() | |
| if(TOOL MATCHES "^map_render$") | |
| list(APPEND TOOL_INCLUDE_DIRS ${PNG_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS}) | |
| - list(APPEND TOOL_DEPS $<TARGET_OBJECTS:engine-gfx>) | |
| + list(APPEND TOOL_DEPS $<TARGET_OBJECTS:engine-gfx> ${GLEW_DEP}) | |
| list(APPEND TOOL_LIBS ${PNG_LIBRARIES} ${FREETYPE_LIBRARIES} ${GLEW_LIBRARIES} ${CMAKE_DL_LIBS} ${EGL_LIBRARY} ${OPENGL_gl_LIBRARY}) | |
| endif() | |
| set(EXCLUDE_FROM_ALL) | |
| @@ -3226,9 +3226,13 @@ if(TOOLS) | |
| src/game/map/render_map.cpp | |
| src/game/map/render_component.cpp | |
| src/game/map/envelope_extrema.cpp | |
| + ${PROJECT_BINARY_DIR}/src/generated/client_data.h | |
| ) | |
| target_include_directories(map_render PRIVATE ${PROJECT_BINARY_DIR}) | |
| target_compile_definitions(map_render PRIVATE BACKEND_NO_SDL) | |
| + if(GLEW_BUNDLED) | |
| + target_compile_definitions(map_render PRIVATE CONF_GLEW_HAS_CONTEXT_INIT) | |
| + endif() | |
| endif() | |
| list(APPEND TARGETS_TOOLS ${TOOL}) | |
| endif() | |
| diff --git a/src/engine/client/backend_egl.cpp b/src/engine/client/backend_egl.cpp | |
| index 1fcf87b26..2d942a405 100644 | |
| --- a/src/engine/client/backend_egl.cpp | |
| +++ b/src/engine/client/backend_egl.cpp | |
| @@ -167,12 +167,23 @@ CGraphicsBackend_EGL::CGraphicsBackend_EGL(TTranslateFunc &&TranslateFunc) : | |
| static bool BackendInitGlew(int &GlewMajor, int &GlewMinor, int &GlewPatch) | |
| { | |
| glewExperimental = GL_TRUE; | |
| +#ifdef CONF_GLEW_HAS_CONTEXT_INIT | |
| const GLenum InitResult = glewContextInit(); | |
| if(InitResult != GLEW_OK) | |
| { | |
| - log_error("gfx", "Unable to init glew: %s", glewGetErrorString(InitResult)); | |
| + log_error("gfx", "Unable to init glew (glewContextInit): %s", glewGetErrorString(InitResult)); | |
| return false; | |
| } | |
| +#else | |
| + const GLenum InitResult = glewInit(); | |
| + // There is no GLX display when rendering headlessly through EGL, in which case glewInit | |
| + // has already initialized the context with glewContextInit internally. | |
| + if(InitResult != GLEW_OK && InitResult != GLEW_ERROR_NO_GLX_DISPLAY) | |
| + { | |
| + log_error("gfx", "Unable to init glew (glewInit): %s", glewGetErrorString(InitResult)); | |
| + return false; | |
| + } | |
| +#endif | |
| #ifdef GLEW_VERSION_4_6 | |
| if(GLEW_VERSION_4_6) | |
| @@ -456,12 +467,16 @@ int CGraphicsBackend_EGL::InitOpenGL(int Width, int Height, int Flags, IStorage | |
| if(InitError != 0) | |
| { | |
| - CCommandProcessorFragment_GLBase::SCommand_Shutdown CmdShutdown; | |
| CCommandBuffer CmdBuffer(1024, 512); | |
| - CmdBuffer.AddCommandUnsafe(CmdShutdown); | |
| - RunBuffer(&CmdBuffer); | |
| - WaitForIdle(); | |
| - CmdBuffer.Reset(); | |
| + if(InitError != -2) | |
| + { | |
| + // shutdown the context, as it might have been initialized | |
| + CCommandProcessorFragment_GLBase::SCommand_Shutdown CmdShutdown; | |
| + CmdBuffer.AddCommandUnsafe(CmdShutdown); | |
| + RunBuffer(&CmdBuffer); | |
| + WaitForIdle(); | |
| + CmdBuffer.Reset(); | |
| + } | |
| StopProcessor(); | |
| delete m_pProcessor; | |
| m_pProcessor = nullptr; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment