fix crash when loading song with no chips
This commit is contained in:
parent
7575e7a4a7
commit
a0df838427
|
@ -1081,7 +1081,7 @@ bool DivEngine::addSystem(DivSystem which) {
|
||||||
song.patchbay.push_back((i<<20)|j);
|
song.patchbay.push_back((i<<20)|j);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
song.patchbay.reserve(outs);
|
if (outs>0) song.patchbay.reserve(outs);
|
||||||
for (unsigned int j=0; j<outs; j++) {
|
for (unsigned int j=0; j<outs; j++) {
|
||||||
song.patchbay.push_back((i<<20)|(j<<16)|j);
|
song.patchbay.push_back((i<<20)|(j<<16)|j);
|
||||||
}
|
}
|
||||||
|
@ -1189,11 +1189,11 @@ bool DivEngine::swapSystem(int src, int dest, bool preserveOrder) {
|
||||||
|
|
||||||
// prepare swap list
|
// prepare swap list
|
||||||
int index=0;
|
int index=0;
|
||||||
swapList.reserve(song.systemLen);
|
if (song.systemLen>0) swapList.reserve(song.systemLen);
|
||||||
for (int i=0; i<song.systemLen; i++) {
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
chanList.clear();
|
chanList.clear();
|
||||||
const int channelCount=getChannelCount(song.system[i]);
|
const int channelCount=getChannelCount(song.system[i]);
|
||||||
chanList.reserve(channelCount);
|
if (channelCount>0) chanList.reserve(channelCount);
|
||||||
for (int j=0; j<channelCount; j++) {
|
for (int j=0; j<channelCount; j++) {
|
||||||
chanList.push_back(index);
|
chanList.push_back(index);
|
||||||
index++;
|
index++;
|
||||||
|
|
|
@ -343,7 +343,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
|
||||||
ds.insLen=16;
|
ds.insLen=16;
|
||||||
}
|
}
|
||||||
logI("reading instruments (%d)...",ds.insLen);
|
logI("reading instruments (%d)...",ds.insLen);
|
||||||
ds.ins.reserve(ds.insLen);
|
if (ds.insLen>0) ds.ins.reserve(ds.insLen);
|
||||||
for (int i=0; i<ds.insLen; i++) {
|
for (int i=0; i<ds.insLen; i++) {
|
||||||
DivInstrument* ins=new DivInstrument;
|
DivInstrument* ins=new DivInstrument;
|
||||||
unsigned char mode=0;
|
unsigned char mode=0;
|
||||||
|
@ -679,7 +679,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
|
||||||
if (ds.version>0x0b) {
|
if (ds.version>0x0b) {
|
||||||
ds.waveLen=(unsigned char)reader.readC();
|
ds.waveLen=(unsigned char)reader.readC();
|
||||||
logI("reading wavetables (%d)...",ds.waveLen);
|
logI("reading wavetables (%d)...",ds.waveLen);
|
||||||
ds.wave.reserve(ds.waveLen);
|
if (ds.waveLen>0) ds.wave.reserve(ds.waveLen);
|
||||||
for (int i=0; i<ds.waveLen; i++) {
|
for (int i=0; i<ds.waveLen; i++) {
|
||||||
DivWavetable* wave=new DivWavetable;
|
DivWavetable* wave=new DivWavetable;
|
||||||
wave->len=(unsigned char)reader.readI();
|
wave->len=(unsigned char)reader.readI();
|
||||||
|
@ -849,7 +849,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
|
||||||
// it appears this byte stored the YMU759 sample rate
|
// it appears this byte stored the YMU759 sample rate
|
||||||
ymuSampleRate=reader.readC();
|
ymuSampleRate=reader.readC();
|
||||||
}
|
}
|
||||||
ds.sample.reserve(ds.sampleLen);
|
if (ds.sampleLen>0) ds.sample.reserve(ds.sampleLen);
|
||||||
for (int i=0; i<ds.sampleLen; i++) {
|
for (int i=0; i<ds.sampleLen; i++) {
|
||||||
DivSample* sample=new DivSample;
|
DivSample* sample=new DivSample;
|
||||||
int length=reader.readI();
|
int length=reader.readI();
|
||||||
|
@ -1961,6 +1961,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logD("systems:");
|
logD("systems:");
|
||||||
|
ds.systemLen=0;
|
||||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||||
unsigned char sysID=reader.readC();
|
unsigned char sysID=reader.readC();
|
||||||
ds.system[i]=systemFromFileFur(sysID);
|
ds.system[i]=systemFromFileFur(sysID);
|
||||||
|
@ -1981,6 +1982,13 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
||||||
tchans=DIV_MAX_CHANS;
|
tchans=DIV_MAX_CHANS;
|
||||||
logW("too many channels!");
|
logW("too many channels!");
|
||||||
}
|
}
|
||||||
|
logV("system len: %d",ds.systemLen);
|
||||||
|
if (ds.systemLen<1) {
|
||||||
|
logE("zero chips!");
|
||||||
|
lastError="zero chips!";
|
||||||
|
delete[] file;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// system volume
|
// system volume
|
||||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||||
|
@ -2369,7 +2377,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
||||||
|
|
||||||
// patchbay
|
// patchbay
|
||||||
unsigned int conns=reader.readI();
|
unsigned int conns=reader.readI();
|
||||||
ds.patchbay.reserve(conns);
|
if (conns>0) ds.patchbay.reserve(conns);
|
||||||
for (unsigned int i=0; i<conns; i++) {
|
for (unsigned int i=0; i<conns; i++) {
|
||||||
ds.patchbay.push_back((unsigned int)reader.readI());
|
ds.patchbay.push_back((unsigned int)reader.readI());
|
||||||
}
|
}
|
||||||
|
@ -6074,7 +6082,6 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) {
|
||||||
if (sys!=DIV_SYSTEM_GB) {
|
if (sys!=DIV_SYSTEM_GB) {
|
||||||
int realVolMacroLen=i->std.volMacro.len;
|
int realVolMacroLen=i->std.volMacro.len;
|
||||||
if (realVolMacroLen>127) realVolMacroLen=127;
|
if (realVolMacroLen>127) realVolMacroLen=127;
|
||||||
w->writeC(realVolMacroLen);
|
|
||||||
if (sys==DIV_SYSTEM_C64_6581 || sys==DIV_SYSTEM_C64_8580) {
|
if (sys==DIV_SYSTEM_C64_6581 || sys==DIV_SYSTEM_C64_8580) {
|
||||||
if (i->std.algMacro.len>0) volIsCutoff=true;
|
if (i->std.algMacro.len>0) volIsCutoff=true;
|
||||||
if (volIsCutoff) {
|
if (volIsCutoff) {
|
||||||
|
@ -6083,15 +6090,18 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) {
|
||||||
}
|
}
|
||||||
realVolMacroLen=i->std.algMacro.len;
|
realVolMacroLen=i->std.algMacro.len;
|
||||||
if (realVolMacroLen>127) realVolMacroLen=127;
|
if (realVolMacroLen>127) realVolMacroLen=127;
|
||||||
|
w->writeC(realVolMacroLen);
|
||||||
for (int j=0; j<realVolMacroLen; j++) {
|
for (int j=0; j<realVolMacroLen; j++) {
|
||||||
w->writeI((-i->std.algMacro.val[j])+18);
|
w->writeI((-i->std.algMacro.val[j])+18);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
w->writeC(realVolMacroLen);
|
||||||
for (int j=0; j<realVolMacroLen; j++) {
|
for (int j=0; j<realVolMacroLen; j++) {
|
||||||
w->writeI(i->std.volMacro.val[j]);
|
w->writeI(i->std.volMacro.val[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
w->writeC(realVolMacroLen);
|
||||||
for (int j=0; j<realVolMacroLen; j++) {
|
for (int j=0; j<realVolMacroLen; j++) {
|
||||||
w->writeI(i->std.volMacro.val[j]);
|
w->writeI(i->std.volMacro.val[j]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue