MOD import: crash fix

This commit is contained in:
tildearrow 2022-03-14 17:16:43 -05:00
parent d7b967c41e
commit 8012676993
3 changed files with 12 additions and 7 deletions

View file

@ -40,6 +40,9 @@
#define DIV_VERSION "dev66" #define DIV_VERSION "dev66"
#define DIV_ENGINE_VERSION 66 #define DIV_ENGINE_VERSION 66
// for imports
#define DIV_VERSION_MOD 0xff01
enum DivStatusView { enum DivStatusView {
DIV_STATUS_NOTHING=0, DIV_STATUS_NOTHING=0,
DIV_STATUS_PATTERN, DIV_STATUS_PATTERN,

View file

@ -1241,6 +1241,7 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) {
try { try {
DivSong ds; DivSong ds;
ds.tuning=436.0; ds.tuning=436.0;
ds.version=DIV_VERSION_MOD;
// check mod magic bytes // check mod magic bytes
if (!reader.seek(1080,SEEK_SET)) { if (!reader.seek(1080,SEEK_SET)) {
@ -1255,6 +1256,7 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) {
&&(magic[0]>='1' && magic[0]<='9' && magic[1]>='0' && magic[1]<='9')) { &&(magic[0]>='1' && magic[0]<='9' && magic[1]>='0' && magic[1]<='9')) {
chCount=((magic[0]-'0')*10)+(magic[1]-'0'); chCount=((magic[0]-'0')*10)+(magic[1]-'0');
} else { } else {
// TODO: Soundtracker MOD?
throw InvalidHeaderException(); throw InvalidHeaderException();
} }
// song name // song name
@ -1266,7 +1268,7 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) {
DivSample* sample=new DivSample; DivSample* sample=new DivSample;
sample->depth=8; sample->depth=8;
sample->name=reader.readString(22); sample->name=reader.readString(22);
int slen=reader.readS_BE()*2; int slen=((unsigned short)reader.readS_BE())*2;
sampLens[i]=slen; sampLens[i]=slen;
if (slen==2) slen=0; if (slen==2) slen=0;
signed char fineTune=reader.readC()&0x0f; signed char fineTune=reader.readC()&0x0f;

View file

@ -3682,7 +3682,7 @@ void FurnaceGUI::doAction(int what) {
} }
break; break;
case GUI_ACTION_SAVE: case GUI_ACTION_SAVE:
if (curFileName=="") { if (curFileName=="" || e->song.version>=0xff00) {
openFileDialog(GUI_FILE_SAVE); openFileDialog(GUI_FILE_SAVE);
} else { } else {
if (save(curFileName,e->song.isDMF?e->song.version:0)>0) { if (save(curFileName,e->song.isDMF?e->song.version:0)>0) {
@ -5438,7 +5438,7 @@ bool FurnaceGUI::loop() {
} }
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("save",BIND_FOR(GUI_ACTION_SAVE))) { if (ImGui::MenuItem("save",BIND_FOR(GUI_ACTION_SAVE))) {
if (curFileName=="") { if (curFileName=="" || e->song.version>=0xff00) {
openFileDialog(GUI_FILE_SAVE); openFileDialog(GUI_FILE_SAVE);
} else { } else {
if (save(curFileName,e->song.isDMF?e->song.version:0)>0) { if (save(curFileName,e->song.isDMF?e->song.version:0)>0) {