fix backend iteration when backend is not compiled

anisotropy
cosmonaut 2022-10-04 10:02:53 -07:00
parent 9aaead40a3
commit fabd31448b
1 changed files with 22 additions and 14 deletions

View File

@ -33,15 +33,22 @@
/* Drivers */ /* Drivers */
#ifdef REFRESH_DRIVER_VULKAN
#define VULKAN_DRIVER &VulkanDriver
#else
#define VULKAN_DRIVER NULL
#endif
#ifdef REFRESH_DRIVER_PS5
#define PS5_DRIVER &PS5Driver
#else
#define PS5_DRIVER NULL
#endif
static const Refresh_Driver *backends[] = { static const Refresh_Driver *backends[] = {
NULL, NULL,
#ifdef REFRESH_DRIVER_VULKAN VULKAN_DRIVER,
&VulkanDriver, PS5_DRIVER
#endif
#ifdef REFRESH_DRIVER_PS5
&PS5Driver,
#endif
NULL
}; };
/* Logging */ /* Logging */
@ -134,14 +141,15 @@ static Refresh_Backend selectedBackend = REFRESH_BACKEND_INVALID;
Refresh_Backend Refresh_SelectBackend(Refresh_Backend preferredBackend, uint32_t *flags) Refresh_Backend Refresh_SelectBackend(Refresh_Backend preferredBackend, uint32_t *flags)
{ {
uint32_t backendIndex, i; uint32_t i;
if (preferredBackend != REFRESH_BACKEND_DONTCARE) if (preferredBackend != REFRESH_BACKEND_DONTCARE)
{ {
/* Try to force it! */ if (backends[preferredBackend] == NULL)
backendIndex = preferredBackend; {
Refresh_LogWarn("Preferred backend was not compiled into this binary! Attempting to fall back!");
if (backends[backendIndex]->PrepareDriver(flags)) }
else if (backends[preferredBackend]->PrepareDriver(flags))
{ {
selectedBackend = preferredBackend; selectedBackend = preferredBackend;
return selectedBackend; return selectedBackend;
@ -150,9 +158,9 @@ Refresh_Backend Refresh_SelectBackend(Refresh_Backend preferredBackend, uint32_t
/* Iterate until we find an appropriate backend. */ /* Iterate until we find an appropriate backend. */
for (i = 1; backends[i] != NULL; i += 1) for (i = 1; i < SDL_arraysize(backends); i += 1)
{ {
if (i != preferredBackend && backends[i]->PrepareDriver(flags)) if (i != preferredBackend && backends[i] != NULL && backends[i]->PrepareDriver(flags))
{ {
selectedBackend = i; selectedBackend = i;
return i; return i;