macOS: Fixed MoltenVK dynamic library loading code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/src/video/cocoa/SDL_cocoavulkan.m b/src/video/cocoa/SDL_cocoavulkan.m
index 2cf55bb..0e53d21 100644
--- a/src/video/cocoa/SDL_cocoavulkan.m
+++ b/src/video/cocoa/SDL_cocoavulkan.m
@@ -58,8 +58,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if (_this->vulkan_config.loader_handle) {
- SDL_SetError("Vulkan/MoltenVK already loaded");
- return -1;
+ return SDL_SetError("Vulkan/MoltenVK already loaded");
}
/* Load the Vulkan loader library */
@@ -80,6 +79,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
_this->vulkan_config.loader_handle = DEFAULT_HANDLE;
} else {
const char** paths;
+ const char *foundPath = NULL;
int numPaths;
int i;
@@ -92,18 +92,17 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
paths = defaultPaths;
numPaths = SDL_arraysize(defaultPaths);
}
-
- for (i=0; i < numPaths; i++) {
- _this->vulkan_config.loader_handle = SDL_LoadObject(paths[i]);
- if (_this->vulkan_config.loader_handle)
- break;
- else
- continue;
+
+ for (i = 0; i < numPaths && _this->vulkan_config.loader_handle == NULL; i++) {
+ foundPath = paths[i];
+ _this->vulkan_config.loader_handle = SDL_LoadObject(foundPath);
+ }
+
+ if (_this->vulkan_config.loader_handle == NULL) {
+ return SDL_SetError("Failed to load Vulkan/MoltenVK library");
}
- if (i == numPaths)
- return -1;
- SDL_strlcpy(_this->vulkan_config.loader_path, paths[i],
+ SDL_strlcpy(_this->vulkan_config.loader_path, foundPath,
SDL_arraysize(_this->vulkan_config.loader_path));
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
_this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");