SDL_DuplicateSurface(3)

πŸ’– NAME πŸ’–

SDL_DuplicateSurface β€” bestie, it makes a brand new surface that's identical to the one you already have. it's giving clone, it's giving twin, it's giving copy-paste but make it ✨official✨


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_surface.h>

SDL_Surface * SDL_DuplicateSurface(SDL_Surface *surface);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea πŸ«– β€” if your original surface has alternate images, the new surface is gonna hold a reference to those same alternate images too. not a separate copy, a reference. iykyk.

and listen, the surface you get back? you gotta free it with SDL_DestroySurface(). like, actually. don't leave it hanging, that's not main character behavior, that's a memory leak πŸ’€


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • surface β€” the surface you wanna duplicate. the one. the only. the original ✨

⭐ RETURN VALUE ⭐

you get back a copy of the surface, slay πŸ’… β€” or NULL if it failed, which is giving flop energy 😭. when that happens, call SDL_GetError() for more info on what went wrong, fr fr.


🧚 THREAD SAFETY 🧚

good news bestie: this one is thread-safe as long as you're calling it on different surfaces from different threads. so like, one thread per surface, and everyone's happy 🌈 no drama, no chaos, just vibes.


πŸ‘‘ AVAILABILITY πŸ‘‘

this iconic function has been available since SDL 3.2.0 πŸŽ‰


πŸ’œ SEE ALSO πŸ’œ

  • SDL_DestroySurface(3) β€” the one you will be calling after this. don't forget. i'm watching πŸ‘€

and that's the whole page, bestie 🫢 this gem lives in the SDL 3.4.18 era of the Simple Directmedia Layer manual, so go forth and duplicate responsibly βœ¨πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from