martindevans / MumbleSharp

An implementation of the mumble voice chat protocol in C#
http://martindevans.me
MIT License
91 stars 28 forks source link

Lazy OpusCode returns null for .NET 4.7.2 #67

Open mentalrob opened 1 year ago

mentalrob commented 1 year ago
protected internal IVoiceCodec GetCodec(SpeechCodecs codec)
        {
            switch (codec)
            {
            case SpeechCodecs.CeltAlpha:
                return this._alpha.Value;
            case SpeechCodecs.Speex:
                return this._speex.Value;
            case SpeechCodecs.CeltBeta:
                return this._beta.Value;
            case SpeechCodecs.Opus:
                return this._opus.Value;
            }
            throw new ArgumentOutOfRangeException("codec");

I'm getting null pointer exception because of this._opus.Value returns null in CodecSet.cs

Platratio34 commented 1 year ago

I am getting something similar, so here is my stack trace:

System.Exception: BasicMumbleProtocol's _encodingThread was terminated unexpectedly because of a System.NullReferenceException
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at MumbleSharp.Audio.Codecs.Opus.OpusDecoder..ctor(Int32 outputSampleRate, Int32 outputChannelCount)
   at MumbleSharp.Audio.Codecs.Opus.OpusCodec..ctor(Int32 sampleRate, Byte sampleBits, Byte channels, UInt16 frameSize)
   at MumbleSharp.Audio.CodecSet.<>c__DisplayClass4_0.<.ctor>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at MumbleSharp.Audio.CodecSet.GetCodec(SpeechCodecs codec)
   at MumbleSharp.Audio.AudioEncodingBuffer.Encode(SpeechCodecs codec)
   at MumbleSharp.BasicMumbleProtocol.EncodingThreadEntry(Exception& exception)
   --- End of inner exception stack trace ---
   at MumbleSharp.BasicMumbleProtocol.<Initialise>b__40_1()
   at System.Threading.Thread.StartCallback()
Meetsch commented 1 year ago

Can you please check that opus.dll is copied over in the output Subfolder "\Audio\Codecs\Opus\Libs\32bit"

Meetsch commented 1 year ago

The Nuget package has been updated to v2.0.1 so that the needed codecs files opus.dll are automatically copied to the output folder of projects referencing the nuget package, this should solve your issue. Please report if it did solve your issue or not, thanks.