diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 3a5b3b7e5..56c0bd2ae 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -884,10 +884,17 @@ bool DivEngine::load(unsigned char* f, size_t slen) { } } + if (active) quitDispatch(); + isBusy.lock(); song.unload(); song=ds; chans=getChannelCount(song.system); renderSamples(); + isBusy.unlock(); + if (active) { + initDispatch(); + syncReset(); + } } catch (EndOfFileException e) { logE("premature end of file!\n"); delete[] file; @@ -1867,6 +1874,7 @@ bool DivEngine::init(String outName) { initDispatch(); reset(); + active=true; if (outName!="") { short* ilBuffer=new short[got.bufsize*2]; @@ -1911,5 +1919,6 @@ bool DivEngine::quit() { quitDispatch(); logI("saving config.\n"); saveConf(); + active=false; return true; } diff --git a/src/engine/engine.h b/src/engine/engine.h index 77778aec6..96e31db50 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -72,6 +72,7 @@ class DivEngine { TAAudio* output; TAAudioDesc want, got; int chans; + bool active; bool playing; bool speedAB; bool endOfSong; @@ -267,6 +268,7 @@ class DivEngine { DivEngine(): chans(0), + active(false), playing(false), speedAB(false), endOfSong(false), diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 9a314df3d..b5a92b037 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -1821,15 +1821,10 @@ int FurnaceGUI::load(String path) { return 1; } fclose(f); - e->quitDispatch(); if (!e->load(file,(size_t)len)) { logE("could not open file!\n"); - e->initDispatch(); - e->syncReset(); return 1; } - e->initDispatch(); - e->syncReset(); } updateWindowTitle(); return 0;