--- gigedit/trunk/src/gigedit/mainwindow.cpp 2021/06/10 12:58:37 3917 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2021/06/10 13:28:17 3918 @@ -2104,6 +2104,10 @@ void Loader::thread_function_sub(gig::progress_t& progress) { RIFF::File* riff = new RIFF::File(filename); + // due to the multi-threaded scenario use separate file I/O handles for + // each thread to avoid file I/O concurrency issues with .gig file + riff->SetIOPerThread(true); + gig = new gig::File(riff); gig->GetInstrument(0, &progress); @@ -2217,6 +2221,10 @@ __clear(); // create a new .gig file (virtually yet) gig::File* pFile = new gig::File; + // due to the multi-threaded scenario use separate file I/O handles for + // each thread to avoid file I/O concurrency issues with .gig file + RIFF::File* pRIFF = pFile->GetRiffFile(); + pRIFF->SetIOPerThread(true); // already add one new instrument by default gig::Instrument* pInstrument = pFile->AddInstrument(); pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument")); @@ -3534,6 +3542,21 @@ file = 0; set_file_is_shared(isSharedInstrument); + // assuming libgig's file-IO-per-thread feature is enabled: by default + // the file stream is closed for individual threads (except of the original + // thread having opened the gig file), so open the file stream for this + // thread for being able to read the .gig file + // (see libgig's RIFF::File::SetIOPerThread() for details) + ::RIFF::File* riff = gig->GetRiffFile(); + if (!riff->IsNew() && riff->GetMode() == ::RIFF::stream_mode_closed) { + try { + riff->SetMode(::RIFF::stream_mode_read); + } catch (...) { + printf("Failed opening '%s' in read mode\n", + riff->GetFileName().c_str()); + } + } + this->filename = (filename && strlen(filename) > 0) ? filename : (!gig->GetFileName().empty()) ?