Fix XM save path to skip sample data after sample headers (#1369)

XM saving failed for files with samples because the save logic only
advanced past sample headers and did not skip the sample data, causing
the next instrument to be written at the wrong position.
This commit is contained in:
EvilGiven
2026-06-27 03:28:50 +08:00
committed by GitHub
parent fa189f6cf7
commit 860406eb98

View File

@@ -457,6 +457,7 @@ bool XM::File::save()
}
unsigned long sampleHeaderSize = 0;
unsigned long sampleDataSize = 0;
if(sampleCount > 0) {
seek(pos + 29);
if(instrumentHeaderSize < 33U || !readU32L(sampleHeaderSize))
@@ -468,9 +469,12 @@ bool XM::File::save()
for(unsigned short j = 0; j < sampleCount; ++ j) {
if(sampleHeaderSize > 4U) {
seek(pos);
if(unsigned long sampleLength = 0; !readU32L(sampleLength))
unsigned long sampleLength = 0;
if(!readU32L(sampleLength))
return false;
sampleDataSize += sampleLength;
if(sampleHeaderSize > 18U) {
seek(pos + 18);
const auto sz = std::min(sampleHeaderSize - 18, 22UL);
@@ -482,6 +486,8 @@ bool XM::File::save()
}
pos += sampleHeaderSize;
}
pos += sampleDataSize;
}
return true;