diff --git a/core/resource.d b/core/resource.d index 5e8ad4f160..e859857d23 100644 --- a/core/resource.d +++ b/core/resource.d @@ -144,7 +144,7 @@ struct ResourceManager char[][] getDir(char[] dir) { dir = FileFinder.addSlash(dir); - char[][] res = listdir(dir); + char[][] res = ((exists(dir) && isdir(dir)) ? listdir(dir) : null); foreach(ref char[] fn; res) fn = dir ~ fn; return res; diff --git a/sound/cpp_avcodec.cpp b/sound/cpp_avcodec.cpp index 7193ae4c62..305fc9573d 100644 --- a/sound/cpp_avcodec.cpp +++ b/sound/cpp_avcodec.cpp @@ -43,7 +43,7 @@ struct MyFile { vector Data; vector DecodedData; }; - vector Streams; + vector Streams; }; // TODO: @@ -75,9 +75,10 @@ extern "C" void cpp_closeAVFile(MyFile *file) for(size_t i = 0;i < file->Streams.size();i++) { - avcodec_close(file->Streams[i].CodecCtx); - file->Streams[i].Data.clear(); - file->Streams[i].DecodedData.clear(); + avcodec_close(file->Streams[i]->CodecCtx); + file->Streams[i]->Data.clear(); + file->Streams[i]->DecodedData.clear(); + delete file->Streams[i]; } file->Streams.clear(); @@ -95,18 +96,20 @@ extern "C" MyFile::MyStream *cpp_getAVAudioStream(MyFile *file, int streamnum) if(streamnum == 0) { - MyFile::MyStream stream; - stream.parent = file; - stream.CodecCtx = file->FmtCtx->streams[i]->codec; - stream.StreamNum = i; - - AVCodec *codec = avcodec_find_decoder(stream.CodecCtx->codec_id); - if(!codec) return NULL; - if(avcodec_open(stream.CodecCtx, codec) < 0) + MyFile::MyStream *stream = new MyFile::MyStream; + stream->parent = file; + stream->CodecCtx = file->FmtCtx->streams[i]->codec; + stream->StreamNum = i; + + AVCodec *codec = avcodec_find_decoder(stream->CodecCtx->codec_id); + if(!codec || avcodec_open(stream->CodecCtx, codec) < 0) + { + delete stream; return NULL; + } file->Streams.push_back(stream); - return &file->Streams[file->Streams.size()-1]; + return stream; } streamnum--; } @@ -130,14 +133,14 @@ static int getNextPacket(MyFile *file) AVPacket packet; while(av_read_frame(file->FmtCtx, &packet) >= 0) { - for(vector::iterator i = file->Streams.begin(); + for(vector::iterator i = file->Streams.begin(); i != file->Streams.end();i++) { - if(i->StreamNum == packet.stream_index) + if((*i)->StreamNum == packet.stream_index) { - size_t idx = i->Data.size(); - i->Data.resize(idx + packet.size); - memcpy(&i->Data[idx], packet.data, packet.size); + size_t idx = (*i)->Data.size(); + (*i)->Data.resize(idx + packet.size); + memcpy(&(*i)->Data[idx], packet.data, packet.size); av_free_packet(&packet); return 0; } diff --git a/sound/music.d b/sound/music.d index dd4dcd531a..3a978c8cba 100644 --- a/sound/music.d +++ b/sound/music.d @@ -40,7 +40,7 @@ struct MusicManager // How much to add to the volume each second when fading const float fadeInRate = 0.10; - const float fadeOutRate = 0.35; + const float fadeOutRate = 0.20; // Maximum buffer length, divided up among OpenAL buffers const uint bufLength = 128*1024; @@ -85,7 +85,6 @@ struct MusicManager outData.length = bufLength / bIDs.length; fileHandle = null; musicOn = false; - updateVolume(); } // Get the new volume setting. @@ -99,7 +98,8 @@ struct MusicManager // a fade. Even if we are fading, though, the volume should never // be over the max. if(fading == Fade.None || volume > maxVolume) volume = maxVolume; - alSourcef(sID, AL_GAIN, volume); + if(sID) + alSourcef(sID, AL_GAIN, volume); } // Give a music play list @@ -154,6 +154,8 @@ struct MusicManager if(checkALError()) fail("Couldn't generate music sources"); alSourcei(sID, AL_SOURCE_RELATIVE, AL_TRUE); + + updateVolume(); } else { @@ -263,7 +265,6 @@ struct MusicManager if(!config.useMusic) return; musicOn = true; - volume = maxVolume; fading = Fade.None; playNext(); } @@ -371,7 +372,7 @@ struct MusicManager else { assert(fading == Fade.Out); - volume -= fadeOutRate * time; + volume -= fadeOutRate * time; if(volume <= 0.0) { fading = Fade.None;