diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index 53c471a316..1b34583f94 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -407,7 +407,7 @@ public: virtual FString GetStats() { FString stats; - size_t pos, len; + size_t pos = 0, len = 0; ALfloat volume; ALint offset; ALint processed; @@ -429,28 +429,34 @@ public: return stats; } - pos = Decoder->getSampleOffset(); - len = Decoder->getSampleLength(); + if (Decoder != nullptr) + { + pos = Decoder->getSampleOffset(); + len = Decoder->getSampleLength(); + } lock.unlock(); stats = (state == AL_INITIAL) ? "Buffering" : (state == AL_STOPPED) ? "Underrun" : (state == AL_PLAYING || state == AL_PAUSED) ? "Ready" : "Unknown state"; - if(state == AL_STOPPED) - offset = BufferCount * (Data.Size()/FrameSize); - else - { - size_t rem = queued*(Data.Size()/FrameSize) - offset; - if(pos > rem) pos -= rem; - else if(len > 0) pos += len - rem; - else pos = 0; - } - pos = (size_t)(pos * 1000.0 / SampleRate); - len = (size_t)(len * 1000.0 / SampleRate); - stats.AppendFormat(",%3u%% buffered", 100 - 100*offset/(BufferCount*(Data.Size()/FrameSize))); - stats.AppendFormat(", %zu.%03zu", pos/1000, pos%1000); - if(len > 0) - stats.AppendFormat(" / %zu.%03zu", len/1000, len%1000); + if (Decoder != nullptr) + { + if (state == AL_STOPPED) + offset = BufferCount * (Data.Size() / FrameSize); + else + { + size_t rem = queued*(Data.Size() / FrameSize) - offset; + if (pos > rem) pos -= rem; + else if (len > 0) pos += len - rem; + else pos = 0; + } + pos = (size_t)(pos * 1000.0 / SampleRate); + len = (size_t)(len * 1000.0 / SampleRate); + stats.AppendFormat(",%3u%% buffered", 100 - 100 * offset / (BufferCount*(Data.Size() / FrameSize))); + stats.AppendFormat(", %zu.%03zu", pos / 1000, pos % 1000); + if (len > 0) + stats.AppendFormat(" / %zu.%03zu", len / 1000, len % 1000); + } if(state == AL_PAUSED) stats += ", paused"; if(state == AL_PLAYING)