Skip to content

Commit 58e378a

Browse files
RyeMuttclaude
andcommitted
Fix Linux link error: resolve XFree without an X11 link dep
createSharedContext's GLX path freed the glXChooseFBConfig result with a direct XFree, but the SDL backend doesn't link libX11 (GLX entry points are resolved through SDL_GL_GetProcAddress), so the ubuntu Viewer build failed to link with "undefined reference to XFree". Resolve XFree from the already-resident libX11 at runtime via SDL_LoadObject / SDL_LoadFunction, matching how the GLX functions are resolved. On the X11 server path libX11 is always loaded; if it can't be found the array is left unfreed (a tiny, bounded, once-per-worker leak) rather than crashing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9c0842b commit 58e378a

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

indra/llwindow/llwindowsdl.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,21 @@ void* LLWindowSDL::createSharedContext()
794794
const int pb_attribs[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, None };
795795
GLXPbuffer pbuf = glx_pbuffer(dpy, fbc[0], pb_attribs);
796796
GLXContext ctx = glx_newctx(dpy, fbc[0], GLX_RGBA_TYPE, share, True);
797-
XFree(fbc);
797+
// glXChooseFBConfig returns an Xlib-allocated array that must be
798+
// released with XFree. The SDL backend doesn't link libX11 (GLX
799+
// is reached through SDL_GL_GetProcAddress), so resolve XFree from
800+
// the already-resident libX11 at runtime via SDL's loader instead
801+
// of taking an X11 link dependency. On the X11 server path libX11
802+
// is always loaded; if XFree can't be found, skip the free (a
803+
// tiny, bounded, once-per-worker-context leak) rather than crash.
804+
if (SDL_SharedObject* x11lib = SDL_LoadObject("libX11.so.6"))
805+
{
806+
if (SDL_FunctionPointer x_free = SDL_LoadFunction(x11lib, "XFree"))
807+
{
808+
((int (*)(void*))x_free)(fbc);
809+
}
810+
SDL_UnloadObject(x11lib);
811+
}
798812
if (pbuf && ctx)
799813
{
800814
shared->glx_dpy = dpy;

0 commit comments

Comments
 (0)