When, on Windows, the application tries to automatically switch to MESA OpenGL library and the system opengl32.dll is not unloaded, prompt the user with a dialog asking to rerun using the --sw-renderer option

This commit is contained in:
enricoturri1966 2022-05-24 10:20:02 +02:00
parent f8ec5fc9e7
commit 6047eec609

View File

@ -66,16 +66,25 @@ public:
return this->success;
}
void unload_opengl_dll()
bool unload_opengl_dll()
{
if (this->hOpenGL) {
BOOL released = FreeLibrary(this->hOpenGL);
if (released)
printf("System OpenGL library released\n");
if (this->hOpenGL != nullptr) {
if (::FreeLibrary(this->hOpenGL) != FALSE) {
if (::GetModuleHandle(L"opengl32.dll") == nullptr) {
printf("System OpenGL library successfully released\n");
this->hOpenGL = nullptr;
return true;
}
else
printf("System OpenGL library released but not removed\n");
}
else
printf("System OpenGL library NOT released\n");
this->hOpenGL = nullptr;
return false;
}
return true;
}
bool is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const
@ -270,20 +279,26 @@ int wmain(int argc, wchar_t **argv)
// https://wiki.qt.io/Cross_compiling_Mesa_for_Windows
// http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/
if (load_mesa) {
opengl_version_check.unload_opengl_dll();
wchar_t path_to_mesa[MAX_PATH + 1] = { 0 };
wcscpy(path_to_mesa, path_to_exe);
wcscat(path_to_mesa, L"mesa\\opengl32.dll");
printf("Loading MESA OpenGL library: %S\n", path_to_mesa);
HINSTANCE hInstance_OpenGL = LoadLibraryExW(path_to_mesa, nullptr, 0);
if (hInstance_OpenGL == nullptr) {
printf("MESA OpenGL library was not loaded\n");
} else
printf("MESA OpenGL library was loaded sucessfully\n");
bool res = opengl_version_check.unload_opengl_dll();
if (!res) {
MessageBox(nullptr, L"PrusaSlicer was unable to automatically switch to MESA OpenGL library\nPlease, try to run the application using the '--sw-renderer' option.\n",
L"PrusaSlicer Warning", MB_OK);
return -1;
}
else {
wchar_t path_to_mesa[MAX_PATH + 1] = { 0 };
wcscpy(path_to_mesa, path_to_exe);
wcscat(path_to_mesa, L"mesa\\opengl32.dll");
printf("Loading MESA OpenGL library: %S\n", path_to_mesa);
HINSTANCE hInstance_OpenGL = LoadLibraryExW(path_to_mesa, nullptr, 0);
if (hInstance_OpenGL == nullptr)
printf("MESA OpenGL library was not loaded\n");
else
printf("MESA OpenGL library was loaded sucessfully\n");
}
}
#endif /* SLIC3R_GUI */
wchar_t path_to_slic3r[MAX_PATH + 1] = { 0 };
wcscpy(path_to_slic3r, path_to_exe);
wcscat(path_to_slic3r, L"PrusaSlicer.dll");