fix crash when loading instrument with samples

This commit is contained in:
tildearrow 2022-11-21 02:55:12 -05:00
parent 1a31b80ea6
commit 82649c9c81

View file

@ -1474,8 +1474,12 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
workingDirIns, workingDirIns,
dpiScale, dpiScale,
[this](const char* path) { [this](const char* path) {
int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(path); std::vector<DivInstrument*> instruments=e->instrumentFromFile(path);
if (!instruments.empty()) { if (!instruments.empty()) {
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
if (curFileDialog==GUI_FILE_INS_OPEN_REPLACE) { if (curFileDialog==GUI_FILE_INS_OPEN_REPLACE) {
if (prevIns==-3) { if (prevIns==-3) {
prevIns=curIns; prevIns=curIns;
@ -3069,10 +3073,14 @@ bool FurnaceGUI::loop() {
break; break;
case SDL_DROPFILE: case SDL_DROPFILE:
if (ev.drop.file!=NULL) { if (ev.drop.file!=NULL) {
int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(ev.drop.file); std::vector<DivInstrument*> instruments=e->instrumentFromFile(ev.drop.file);
DivWavetable* droppedWave=NULL; DivWavetable* droppedWave=NULL;
DivSample* droppedSample=NULL;; DivSample* droppedSample=NULL;;
if (!instruments.empty()) { if (!instruments.empty()) {
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
if (!e->getWarnings().empty()) { if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC); showWarning(e->getWarnings(),GUI_WARN_GENERIC);
} }
@ -4160,6 +4168,7 @@ bool FurnaceGUI::loop() {
bool ask=false; bool ask=false;
bool warn=false; bool warn=false;
String warns="there were some warnings/errors while loading instruments:\n"; String warns="there were some warnings/errors while loading instruments:\n";
int sampleCountBefore=e->song.sampleLen;
for (String i: fileDialog->getFileName()) { for (String i: fileDialog->getFileName()) {
std::vector<DivInstrument*> insTemp=e->instrumentFromFile(i.c_str()); std::vector<DivInstrument*> insTemp=e->instrumentFromFile(i.c_str());
if (insTemp.empty()) { if (insTemp.empty()) {
@ -4174,6 +4183,9 @@ bool FurnaceGUI::loop() {
instruments.push_back(j); instruments.push_back(j);
} }
} }
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
if (warn) { if (warn) {
if (instruments.empty()) { if (instruments.empty()) {
if (fileDialog->getFileName().size()>1) { if (fileDialog->getFileName().size()>1) {
@ -4203,8 +4215,12 @@ bool FurnaceGUI::loop() {
break; break;
} }
case GUI_FILE_INS_OPEN_REPLACE: { case GUI_FILE_INS_OPEN_REPLACE: {
int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(copyOfName.c_str()); std::vector<DivInstrument*> instruments=e->instrumentFromFile(copyOfName.c_str());
if (!instruments.empty()) { if (!instruments.empty()) {
if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP();
}
if (!e->getWarnings().empty()) { if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC); showWarning(e->getWarnings(),GUI_WARN_GENERIC);
} }