# sdl2-compat: render: match SDL2's handling of bogus values in SDL\_HINT\_RENDER\_DRIVER.

**URL:** <https://discourse.libsdl.org/t/sdl2-compat-render-match-sdl2s-handling-of-bogus-values-in-sdl-hint-render-driver/57579>\
**Category:** SDL Commits\
**Created:** [February 4, 2025, 6:24pm UTC](https://discourse.libsdl.org/t/sdl2-compat-render-match-sdl2s-handling-of-bogus-values-in-sdl-hint-render-driver/57579 "2025-02-04T18:24:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [February 4, 2025, 6:24pm UTC](https://discourse.libsdl.org/t/sdl2-compat-render-match-sdl2s-handling-of-bogus-values-in-sdl-hint-render-driver/57579/1 "2025-02-04T18:24:07Z")

</div>

> <https://github.com/libsdl-org/sdl2-compat/commit/e4332ceb5b48129be126a819743b850576376f4f>
>
> Fixes #305.

```diff
From e4332ceb5b48129be126a819743b850576376f4f Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 4 Feb 2025 13:23:26 -0500
Subject: [PATCH] render: match SDL2's handling of bogus values in
 SDL_HINT_RENDER_DRIVER.

Fixes #305.
---
 src/sdl2_compat.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index bbfd64c..84c4c5c 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -4556,8 +4556,31 @@ SDL_CreateRenderer(SDL_Window *window, int idx, Uint32 flags)
     SDL_PropertiesID props;
     SDL_Renderer *renderer;
     const char *name = NULL;
+ char *namecpy = NULL;
 
- if (idx != -1) {
+ if (idx == -1) {
+ /* SDL2, if given a bogus render driver name in a hint, would find no match, and then try everything.
+ SDL3 reports failure in this case. PCem tries to create a renderer named "auto" so we need to deal
+ with this. */
+ name = SDL3_GetHint(SDL_HINT_RENDER_DRIVER);
+ if (name) {
+ const int total = SDL3_GetNumRenderDrivers();
+ int i;
+ for (i = 0; i < total; i++) {
+ if (SDL3_strcasecmp(name, SDL3_GetRenderDriver(i)) == 0) {
+ break;
+ }
+ }
+ if (i == total) {
+ namecpy = SDL3_strdup(name);
+ if (!namecpy) {
+ return NULL;
+ }
+ name = NULL; /* set it to NULL so SDL3 will choose a default. */
+ SDL3_SetHint(SDL_HINT_RENDER_DRIVER, NULL);
+ }
+ }
+ } else {
         name = SDL3_GetRenderDriver(idx);
         if (!name) {
             return NULL; /* assume SDL3_GetRenderDriver set the SDL error. */
@@ -4588,6 +4611,12 @@ SDL_CreateRenderer(SDL_Window *window, int idx, Uint32 flags)
         SDL3_SetRenderVSync(renderer, 1);
     }
 
+ /* restore original hint. */
+ if (namecpy) {
+ SDL3_SetHint(SDL_HINT_RENDER_DRIVER, namecpy);
+ SDL3_free(namecpy);
+ }
+
     return renderer;
 }
 

```
