sdl2: fix CXX_BUILD=1 by hoisting struct sdl2_overlay to file scope

struct sdl2_overlay was defined inline inside the _sdl2_video struct
body in sdl2_common.h. In C the tag leaks to file scope, so
sdl2_gfx.c could freely declare 'struct sdl2_overlay *o'. In C++ a
struct defined inside another struct is scoped to the enclosing type
(_sdl2_video::sdl2_overlay), so under CXX_BUILD=1 the file-scope
references in sdl2_overlay_load() and sdl2_overlays_render() resolved
to a different, incomplete 'sdl2_overlay', producing:

  cannot convert '_sdl2_video::sdl2_overlay*' to
    'sdl2_overlay_load(...)::sdl2_overlay*'
  invalid use of incomplete type 'struct ...::sdl2_overlay'

Move the struct definition out to file scope (still under
HAVE_OVERLAY) and reference it as 'struct sdl2_overlay *overlays;' in
the member. This yields a single shared type in both C and C++; the
layout and the C build are unchanged.

Follow-up to the CXX_BUILD fixes in 059ca26 / 7712d87.
This commit is contained in:
libretroadmin authored and libretroadmin committed 2026-06-25 09:54:48 +02:00
1 parent 7712d87b3c
commit a624ae15bb
1 file changed
+26 -11
+26 -11
View File
@@ -42,6 +42,22 @@ typedef struct sdl2_tex
bool rgb32;
} sdl2_tex_t;
#ifdef HAVE_OVERLAY
/* On-screen input overlay entry. Defined at file scope (not inside
* _sdl2_video) so the tag resolves to the same type in both C and C++;
* see the note at the 'overlays' member below. */
struct sdl2_overlay
{
SDL_Texture *tex;
unsigned tex_w;
unsigned tex_h;
float tex_coords[4];
float vert_coords[4];
float alpha_mod;
bool fullscreen;
};
#endif
typedef struct _sdl2_video
{
double rotation;
@@ -75,17 +91,16 @@ typedef struct _sdl2_video
* 0..1 normalised space. vertex_geom flips y to (1.0f - y) and
* negates h, matching d3d8 / gl / d3d9_common; vertex_geom
* comments document the rationale - we undo the flip at render
* time in sdl2_overlays_render. */
struct sdl2_overlay
{
SDL_Texture *tex;
unsigned tex_w;
unsigned tex_h;
float tex_coords[4];
float vert_coords[4];
float alpha_mod;
bool fullscreen;
} *overlays;
* time in sdl2_overlays_render.
*
* Note: struct sdl2_overlay is defined at file scope (above this
* typedef) rather than inline here. Defining a struct inside
* another struct's body scopes the tag to the enclosing type in
* C++ (sdl2_video::sdl2_overlay), so under CXX_BUILD a file-scope
* 'struct sdl2_overlay *' in sdl2_gfx.c would refer to a different,
* incomplete type. A top-level definition keeps a single shared
* type in both C and C++. */
struct sdl2_overlay *overlays;
unsigned overlays_size;
bool overlays_enabled;
#endif