diff --git a/examples/MusPlay-Qt/SingleApplication/singleapplication.cpp b/examples/MusPlay-Qt/SingleApplication/singleapplication.cpp index 1be086af..8154242e 100644 --- a/examples/MusPlay-Qt/SingleApplication/singleapplication.cpp +++ b/examples/MusPlay-Qt/SingleApplication/singleapplication.cpp @@ -35,19 +35,22 @@ SingleApplication::SingleApplication(QStringList &args) : _shouldContinue = false; // By default this is not the main process socket = new QUdpSocket(); - server = NULL; + server = nullptr; QString isServerRuns; bool isRunning=false; m_sema.acquire();//Avoid races - if(m_shmem.attach()) //Detect shared memory copy - { - isRunning = true; - } - else + + if(!m_shmem.create(1))//Detect shared memory copy { - m_shmem.create(1); - isRunning = false; + m_shmem.attach(); + m_shmem.detach(); + if(!m_shmem.create(1)) + { + isRunning = true; + if(!m_shmem.attach()) + qWarning() << "Can't re-attach existing shared memory!"; + } } //Force run second copy of application diff --git a/src/codecs/music_gme.c b/src/codecs/music_gme.c index 0c387e24..9906a35c 100644 --- a/src/codecs/music_gme.c +++ b/src/codecs/music_gme.c @@ -138,6 +138,8 @@ GME_Music *GME_LoadSongRW(SDL_RWops *src, int trackNum) /* Set infinite playback */ gme_set_fade(music->game_emu, -1); + /* For old versions, for newer the next call is supported: */ + /* gme_set_autoload_playback_limit(music->game_emu, 0); */ music->volume = MIX_MAX_VOLUME; music->tempo = 1.0; diff --git a/src/music.c b/src/music.c index b7dc74a5..0ce96bf3 100644 --- a/src/music.c +++ b/src/music.c @@ -665,8 +665,8 @@ static Mix_MusicType xmi_compatible_midi_player() #ifdef MUSIC_MID_ADLMIDI static int detect_imf(SDL_RWops *in, Sint64 start) { - Uint16 chunksize, buff, i = 42; - Uint32 sum1 = 0, sum2 = 0; + Uint16 chunksize, buff; + Uint32 sum1 = 0, sum2 = 0, passed_length = 0; Uint16 word; if(!in) @@ -684,22 +684,27 @@ static int detect_imf(SDL_RWops *in, Sint64 start) return 0; } - while (i > 0) { + while (passed_length < chunksize) { if (SDL_RWread(in, &word, 1, 2) != 2) { SDL_RWseek(in, start, RW_SEEK_SET); break; } + passed_length += 2; buff = SDL_SwapLE16(word); sum1 += buff; if (SDL_RWread(in, &word, 1, 2) != 2) { SDL_RWseek(in, start, RW_SEEK_SET); break; } + passed_length += 2; buff = SDL_SwapLE16(word); sum2 += buff; - i--; } SDL_RWseek(in, start, RW_SEEK_SET); + + if (passed_length != chunksize) + return 0; + return (sum1 > sum2); }