Handle SDL_Surface changes
This does mean we'll need to translate between SDL2 and SDL3 surfaces in sdl2-compat though.
We need to do this anyhow, since we added SDL_PropertiesID to the struct. Right now sdl2-compat works with surfaces as long as you only use them as opaque objects, but would explode if you allocate your own or try to access its fields.
Originally posted by @icculus in https://github.com/libsdl-org/SDL/issues/8633#issuecomment-1858890216
I can try to have a look to this !
ok, here's some experiment : https://github.com/libsdl-org/sdl2-compat/pull/119/files
can be tested by patching SDL3, so that SDL_Surface really changes !
diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h
index fcc8c1d2c..601d36cb5 100644
--- a/include/SDL3/SDL_surface.h
+++ b/include/SDL3/SDL_surface.h
@@ -97,6 +97,7 @@ typedef enum
*/
typedef struct SDL_Surface
{
+ int dummy[20]; /**< Read-only */
Uint32 flags; /**< Read-only */
SDL_PixelFormat *format; /**< Read-only */
int w, h; /**< Read-only */
testsprite2 seems to work fine. some other also.
but:
- very likely I've made some error because there's a lot of functions.
- I think some functions needs more works, like maintaining a pair SDL2_Surface/SDL3_Surface. (Maybe all ?)
SDL_CreateSoftwareRenderer(SDL2_Surface *s2)
SDL_GetWindowSurface(SDL_Window *a),
...
- testautomation crash. in fact, there's an issue SDL_pixels.c : SDL_InvalidateMap(SDL_BlitMap *map) and SDL internals, we keep a reference other surface blitmap ( SDL_ListRemove((SDL_ListNode **)&(map->dst->list_blitmap), map); ) so that's crash here. unless we always keep pairs SDL2_Surface/SDL3_Surface.
-> I think SDL3 would also crash, If the surface is manually created stack-allocated.
( maybe we revert this https://github.com/libsdl-org/SDL/commit/ebc12a2fd2bb692908884e7db6cc935941a591f2 )