Commit 0eb0a816 by Kenneth Russell

Fix seg fault in IsPlatformAvailable.

Some GLX implementations can't handle having libGL.so.1 dlclose'd out from under them while there's any X window still open against which a GLXWindow was ever created. Load the library once per process rather than once per FunctionsGLX instance. This showed up as a crash in X11Window::destroy, during XCloseDisplay. BUG=angleproject:892 Change-Id: I0da2674786a952865e5bea2513259c0a32d4453c Reviewed-on: https://chromium-review.googlesource.com/280902Tested-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@google.com>
parent 57cdc69c
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
namespace rx namespace rx
{ {
void* FunctionsGLX::sLibHandle = nullptr;
template<typename T> template<typename T>
static bool GetProc(PFNGETPROCPROC getProc, T *member, const char *name) static bool GetProc(PFNGETPROCPROC getProc, T *member, const char *name)
{ {
...@@ -88,7 +90,6 @@ struct FunctionsGLX::GLXFunctionTable ...@@ -88,7 +90,6 @@ struct FunctionsGLX::GLXFunctionTable
FunctionsGLX::FunctionsGLX() FunctionsGLX::FunctionsGLX()
: majorVersion(0), : majorVersion(0),
minorVersion(0), minorVersion(0),
mLibHandle(nullptr),
mXDisplay(nullptr), mXDisplay(nullptr),
mXScreen(-1), mXScreen(-1),
mFnPtrs(new GLXFunctionTable()) mFnPtrs(new GLXFunctionTable())
...@@ -107,17 +108,23 @@ bool FunctionsGLX::initialize(Display *xDisplay, int screen, std::string *errorS ...@@ -107,17 +108,23 @@ bool FunctionsGLX::initialize(Display *xDisplay, int screen, std::string *errorS
mXDisplay = xDisplay; mXDisplay = xDisplay;
mXScreen = screen; mXScreen = screen;
mLibHandle = dlopen("libGL.so.1", RTLD_NOW); // Some OpenGL implementations can't handle having this library
if (!mLibHandle) // handle closed while there's any X window still open against
// which a GLXWindow was ever created.
if (!sLibHandle)
{ {
*errorString = std::string("Could not dlopen libGL.so.1: ") + dlerror(); sLibHandle = dlopen("libGL.so.1", RTLD_NOW);
return false; if (!sLibHandle)
{
*errorString = std::string("Could not dlopen libGL.so.1: ") + dlerror();
return false;
}
} }
getProc = reinterpret_cast<PFNGETPROCPROC>(dlsym(mLibHandle, "glXGetProcAddress")); getProc = reinterpret_cast<PFNGETPROCPROC>(dlsym(sLibHandle, "glXGetProcAddress"));
if (!getProc) if (!getProc)
{ {
getProc = reinterpret_cast<PFNGETPROCPROC>(dlsym(mLibHandle, "glXGetProcAddressARB")); getProc = reinterpret_cast<PFNGETPROCPROC>(dlsym(sLibHandle, "glXGetProcAddressARB"));
} }
if (!getProc) if (!getProc)
{ {
...@@ -212,11 +219,6 @@ bool FunctionsGLX::initialize(Display *xDisplay, int screen, std::string *errorS ...@@ -212,11 +219,6 @@ bool FunctionsGLX::initialize(Display *xDisplay, int screen, std::string *errorS
void FunctionsGLX::terminate() void FunctionsGLX::terminate()
{ {
if (mLibHandle)
{
dlclose(mLibHandle);
mLibHandle = nullptr;
}
} }
bool FunctionsGLX::hasExtension(const char *extension) const bool FunctionsGLX::hasExtension(const char *extension) const
......
...@@ -73,7 +73,7 @@ class FunctionsGLX ...@@ -73,7 +73,7 @@ class FunctionsGLX
struct GLXFunctionTable; struct GLXFunctionTable;
void *mLibHandle; static void *sLibHandle;
Display *mXDisplay; Display *mXDisplay;
int mXScreen; int mXScreen;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment