SDL_image: Seek stream to the beginning if error in IMG_SaveWEBP_IO (#574)

From da777b32777e0c72e0fa8edeb8edc950d6397956 Mon Sep 17 00:00:00 2001
From: Xen <[EMAIL REDACTED]>
Date: Wed, 30 Jul 2025 03:48:23 +0300
Subject: [PATCH] Seek stream to the beginning if error in IMG_SaveWEBP_IO
 (#574)

IMG_LoadWEBP_IO and IMG_LoadWEBPAnimation_IO_Internal get the position at the beginning and set it back to sthe tream if the operation fails. Following this standard, the same added to our new save function, so it behaves the same.
---
 src/IMG_webp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/IMG_webp.c b/src/IMG_webp.c
index fd0274b8..9911f22f 100644
--- a/src/IMG_webp.c
+++ b/src/IMG_webp.c
@@ -531,12 +531,15 @@ bool IMG_SaveWEBP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, floa
     bool pic_initialized = false;
     bool memorywriter_initialized = false;
     bool converted_surface_locked = false;
+    Sint64 start = -1;
 
     if (!surface || !dst) {
         error = "Invalid input surface or destination stream.";
         goto cleanup;
     }
 
+    start = SDL_TellIO(dst);
+
     if (!IMG_InitWEBP()) {
         error = SDL_GetError();
         goto cleanup;
@@ -635,6 +638,9 @@ bool IMG_SaveWEBP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, floa
     }
 
     if (error) {
+        if (!closeio && start != -1) {
+            SDL_SeekIO(dst, start, SDL_IO_SEEK_SET);
+        }
         SDL_SetError("%s", error);
         ret = false;
     }