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

[linux] Segfault when starting OpenGL render device #1761

Open
alsed opened this issue Jan 3, 2025 · 2 comments
Open

[linux] Segfault when starting OpenGL render device #1761

alsed opened this issue Jan 3, 2025 · 2 comments
Labels
Bug The issue in the run-time.

Comments

@alsed
Copy link
Contributor

alsed commented Jan 3, 2025

Describe the bug
A segmentation fault occurs when starting the engine, specifically when tries to start the render device (openGL).
The problem is not consistent, happens most of the time, but not always.
Occurs in XrCore.so

To Reproduce

  1. Compile rpm package in debug mode.
  2. Install.
  3. Execute xd_3da (on linux and default openGL render)
  4. See error

Expected behavior
Engine starts

Screenshots, videos
N/A

BugTrap error report

[...]
Starting RENDER device...
 
FATAL ERROR
 
[error] Expression    : <no expression>
[error] Function      : handler_base
[error] File          : /home/alsed/Descargas/xray-16/src/xrCore/xrDebug.cpp
[error] Line          : 860
[error] Description   : segmentation fault
 

stack trace:

xrDebug::GatherInfo(char*, unsigned long, ErrorLocation const&, char const*, char const*, char const*, char const*)
xrDebug::Fail(bool&, ErrorLocation const&, char const*, char const*, char const*, char const*)
/lib64/xrCore.so(+0x1ab2b) [0x7f0123348b2b]
/lib64/xrCore.so(+0x1ab6a) [0x7f0123348b6a]
/lib64/libc.so.6(+0x1a090) [0x7f0122826090]
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:763: FINISHME: support YUV colorspace with DRM format modifiers
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:794: FINISHME: support more multi-planar formats with DRM modifiers

Desktop (please complete the following information):

  • OS: Fedora 41
  • OpenXRay dev version

Additional context

  • Engine compiled in debug mode.

When debugging, I get this info:

#0  __GI_getenv (name=name@entry=0x7ffff4182d1c "EGL_KHR_create_context") at getenv.c:50

#1  0x00007ffff40dc510 in SDL_getenv_REAL (name=0x7ffff4182d1c "EGL_KHR_create_context") at /usr/src/debug/SDL2-2.30.9-1.fc41.x86_64/src/stdlib/SDL_getenv.c:183

#2  SDL_EGL_HasExtension (_this=_this@entry=0x437ed0, type=type@entry=SDL_EGL_DISPLAY_EXTENSION, ext=ext@entry=0x7ffff4182d1c "EGL_KHR_create_context")
    at /usr/src/debug/SDL2-2.30.9-1.fc41.x86_64/src/video/SDL_egl.c:193

#3  0x00007ffff40df489 in SDL_EGL_CreateContext (_this=0x437ed0, egl_surface=0x1c22440) at /usr/src/debug/SDL2-2.30.9-1.fc41.x86_64/src/video/SDL_egl.c:994

#4  0x00007ffff412d811 in Wayland_GLES_CreateContext (_this=0x437ed0, window=<optimized out>) at /usr/src/debug/SDL2-2.30.9-1.fc41.x86_64/src/video/wayland/SDL_waylandopengles.c:54

#5  0x00007ffff40ec615 in SDL_GL_CreateContext_REAL (window=0x4b58b0) at /usr/src/debug/SDL2-2.30.9-1.fc41.x86_64/src/video/SDL_video.c:4094

#6  0x00007fffbf25d3b0 in CHW::CreateDevice(SDL_Window*) () from /lib64/xrRender_GL.so
  • Only function 6, CHW::CreateDevice(SDL_Window*) () is from the engine, 5 to 0 are all SDL internal functions.
  • The problem seems to occur because a memory address is being passed as if were a valid pointer to a char. This occurs in SDL_getenv_REAL, which is receiving name=0x7ffffff4182d1c “EGL_KHR_create_context”. SDL_getenv expects a const char * as a parameter.
  • I suspect somewhere in the stack the pointer gets invalid or corrupted.
@alsed alsed added the Bug The issue in the run-time. label Jan 3, 2025
@alsed
Copy link
Contributor Author

alsed commented Jan 6, 2025

Investigating these, it seems that CreateDevice() has not just one but several instances where it can segfault.

For the error when calling SDL_GL_CreateContext I've found a workaround. For some reason this function does not like to work with global variables, but a locally created variable can call the function without problems and then assign its value to m_context.

// Create the primary context workaround 
    SDL_GLContext m_glcontext{};
    m_glcontext = SDL_GL_CreateContext(m_window);
    
    m_context = m_glcontext;  // copy the value
    
    // Local variable no longer needed
    SDL_GL_DeleteContext(m_glcontext);
    m_glcontext = nullptr;
    
    // Assert
    if (m_context == nullptr)
    {
        Log("! Could not create openGL context:", SDL_GetError());
    }

The errors don't end there. I've also found that the it's best to avoid call MakeContextCurrent(IRender::PrimaryContext and instead make the call directly.:

if (! (SDL_GL_MakeCurrent(m_window, m_context)))
{
	Log("! Could not assign primary context as current:", SDL_GetError());
}

Finally, frequent errors also occur when openGL functions are called, for example glDebugMessageCallback if in DEBUG mode, or with glGetIntegerv.
I suspect this has to do with requiring GLAD to be able to be used, but I'm not sure.

@Xottab-DUTY
Copy link
Member

Can you generate GLAD with gladLoadGLLoader function and try to use it instead to see if it solves the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue in the run-time.
Projects
Status: No status
Development

No branches or pull requests

2 participants