Pass SDL major version between ref and client, bump ref API version.

SDL major versions must not be combined in one process, otherwise bad
things will happen. In the best case the game crashes, in the worst case
strange bugs will occure. To prevent that:

* Add a new field `framework_version` to the renderer API and use it to
  pass the SDL major version from the renderer to client. Don't load the
  renderer if it and the client were build with different SDL major
  versions.
* Bump the renderer API version to 7. This could have been implemented
  by assuming `framework_version == 0` (not filled by renderer) as SDL
  2, but let's keep things clean and bump the version.

While here fix a long standing bug with printing the error when not
loading a renderer lib. The message must be generated before shutting
down the renderer, otherwise the API version will alsways be 0. The
struct is zeroed at renderer shutdown.
This commit is contained in:
Yamagi 2024-04-06 10:22:09 +02:00
parent 78c951d620
commit 23f60d25b1
12 changed files with 89 additions and 2 deletions

View file

@ -1916,6 +1916,7 @@ GetRefAPI(refimport_t imp)
ri = imp;
re.api_version = API_VERSION;
re.framework_version = RI_GetSDLVersion();
re.Init = RI_Init;
re.Shutdown = RI_Shutdown;

View file

@ -310,3 +310,21 @@ RI_ShutdownContext(void)
}
}
}
/*
* Returns the SDL major version. Implemented
* here to not polute gl1_main.c with the SDL
* headers.
*/
int RI_GetSDLVersion()
{
#ifdef USE_SDL3
SDL_Version ver;
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
return ver.major;
}

View file

@ -447,6 +447,13 @@ void *RI_GetProcAddress (const char* proc);
*/
void RI_GetDrawableSize(int* width, int* height);
/*
* Returns the SDL major version. Implemented
* here to not polute gl1_main.c with the SDL
* headers.
*/
int RI_GetSDLVersion();
/* g11_draw */
extern image_t * RDraw_FindPic(char *name);
extern void RDraw_GetPicSize(int *w, int *h, char *pic);

View file

@ -1997,6 +1997,7 @@ GetRefAPI(refimport_t imp)
ri = imp;
re.api_version = API_VERSION;
re.framework_version = GL3_GetSDLVersion();
re.Init = GL3_Init;
re.Shutdown = GL3_Shutdown;

View file

@ -459,3 +459,21 @@ void GL3_ShutdownContext()
}
}
}
/*
* Returns the SDL major version. Implemented
* here to not polute gl3_main.c with the SDL
* headers.
*/
int GL3_GetSDLVersion()
{
#ifdef USE_SDL3
SDL_Version ver;
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
return ver.major;
}

View file

@ -395,6 +395,7 @@ extern qboolean GL3_IsVsyncActive(void);
extern void GL3_EndFrame(void);
extern void GL3_SetVsync(void);
extern void GL3_ShutdownContext(void);
extern int GL3_GetSDLVersion(void);
// gl3_misc.c
extern void GL3_InitParticleTexture(void);

View file

@ -1813,10 +1813,19 @@ GetRefAPI(refimport_t imp)
// used different variable name for prevent confusion and cppcheck warnings
refexport_t refexport;
// Need to communicate the SDL major version to the client.
#ifdef USE_SDL3
SDL_Version ver;
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
memset(&refexport, 0, sizeof(refexport_t));
ri = imp;
refexport.api_version = API_VERSION;
refexport.framework_version = ver.major;
refexport.BeginRegistration = RE_BeginRegistration;
refexport.RegisterModel = RE_RegisterModel;

View file

@ -819,3 +819,12 @@ GLimp_GetWindowDisplayIndex(void)
{
return last_display;
}
int
GLimp_GetFrameworkVersion(void)
{
SDL_version ver;
SDL_VERSION(&ver);
return ver.major;
}

View file

@ -902,3 +902,12 @@ GLimp_GetWindowDisplayIndex(void)
{
return last_display;
}
int
GLimp_GetFrameworkVersion(void)
{
SDL_Version ver;
SDL_VERSION(&ver);
return ver.major;
}

View file

@ -125,7 +125,7 @@ typedef enum {
} ref_restart_t;
// FIXME: bump API_VERSION?
#define API_VERSION 6
#define API_VERSION 7
#define EXPORT
#define IMPORT
@ -137,6 +137,11 @@ typedef struct
// if api_version is different, the dll cannot be used
int api_version;
// if framework_version is different, the dll cannot be used
// necessary because differend SDL major version cannot be
// mixed.
int framework_version;
// called when the library is loaded
qboolean (EXPORT *Init) (void);

View file

@ -66,5 +66,6 @@ void GLimp_ShutdownGraphics(void);
void GLimp_GrabInput(qboolean grab);
float GLimp_GetRefreshRate(void);
qboolean GLimp_GetDesktopMode(int *pwidth, int *pheight);
int GLimp_GetFrameworkVersion(void);
#endif

View file

@ -455,9 +455,17 @@ VID_LoadRenderer(void)
// Let's check if we've got a compatible renderer.
if (re.api_version != API_VERSION)
{
Com_Printf("%s has incompatible api_version %d!\n", reflib_name, re.api_version);
VID_ShutdownRenderer();
Com_Printf("%s has incompatible api_version %d!\n", reflib_name, re.api_version);
return false;
}
else if (re.framework_version != GLimp_GetFrameworkVersion())
{
Com_Printf("%s has incompatible sdl_version %d!\n", reflib_name, re.framework_version);
VID_ShutdownRenderer();
return false;
}