From 91fbc01ed06b89e463ee7455a726d867f188ec96 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 11 Mar 2026 05:10:50 +0300
Subject: [PATCH] music_xmp.c: handle tricky xmp_set_position() return code
better
backport of SDL3_mixer commit e50ed674630353f663f2bc314eb758d6d8f1e2fe
(cherry picked from commit 541990a44534a26356ce69693bb66a0c867f6910)
---
src/codecs/music_xmp.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/codecs/music_xmp.c b/src/codecs/music_xmp.c
index 83bf9df14..a894f3715 100644
--- a/src/codecs/music_xmp.c
+++ b/src/codecs/music_xmp.c
@@ -150,7 +150,7 @@ typedef struct
static int XMP_Seek(void *ctx, double pos);
static void XMP_Delete(void *ctx);
-static void libxmp_set_error(int e)
+static int libxmp_set_error(int e)
{
const char *msg;
switch (e) {
@@ -179,7 +179,7 @@ static void libxmp_set_error(int e)
msg = "Unknown error";
break;
}
- Mix_SetError("XMP: %s", msg);
+ return Mix_SetError("XMP: %s", msg);
}
static unsigned long xmp_fread(void *dst, unsigned long len, unsigned long nmemb, void *src)
@@ -372,7 +372,13 @@ static int XMP_GetAudio(void *context, void *data, int bytes)
static int XMP_Jump(void *context, int order)
{
XMP_Music *music = (XMP_Music *)context;
- return libxmp.xmp_set_position(music->ctx, order);
+ int err = libxmp.xmp_set_position(music->ctx, order);
+ switch (err) {
+ case -XMP_ERROR_STATE:
+ case -XMP_ERROR_INVALID:
+ return libxmp_set_error(err);
+ }
+ return 0;
}
/* Jump (seek) to a given position */