HomelessMage/Zvezda-Bundle

VOIP

HomelessMage opened this issue · 1 comments

Exception: Object reference not set to an instance of an object. (System.NullReferenceException)
Target site: Void UpdateVoipSound()
Stack trace: 
   at Barotrauma.Networking.Client.UpdateVoipSound() in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\Client.cs:line 114
   at Barotrauma.Networking.GameClient.Update(Single deltaTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Networking\GameClient.cs:line 469
   at Barotrauma.GameMain.Update(GameTime gameTime) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\GameMain.cs:line 904
   at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime) in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 656
   at Microsoft.Xna.Framework.Game.Tick() in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 500
   at Microsoft.Xna.Framework.SdlGamePlatform.RunLoop() in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\SDL\SDLGamePlatform.cs:line 93
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 397
   at Microsoft.Xna.Framework.Game.Run() in <DEV>\Libraries\MonoGame.Framework\Src\MonoGame.Framework\Game.cs:line 367
   at Barotrauma.Program.Main(String[] args) in <DEV>\Barotrauma\BarotraumaClient\ClientSource\Program.cs:line 58
public void UpdateVoipSound() {
  if (VoipSound == null || !VoipSound.IsPlaying) {
    radioNoiseChannel?.Dispose();
    radioNoiseChannel = null;
    if (VoipSound != null) {
      DebugConsole.Log("Destroying voipsound");
      VoipSound.Dispose();
    }
    VoipSound = null;
    return;
  }

  if (Screen.Selected is ModDownloadScreen) {
    VoipSound.Gain = 0.0 f;
  }

  float gain = 1.0 f;
  float noiseGain = 0.0 f;
  Vector3 ? position = null;
  if (character != null) {
    if (GameSettings.CurrentConfig.Audio.UseDirectionalVoiceChat) {
      position = new Vector3(character.WorldPosition.X, character.WorldPosition.Y, 0.0 f);
    } else {
      float dist = Vector3.Distance(new Vector3(character.WorldPosition, 0.0 f), GameMain.SoundManager.ListenerPosition);
      gain = 1.0 f - MathUtils.InverseLerp(VoipSound.Near, VoipSound.Far, dist);
    }
    if (RadioNoise > 0.0 f) {
      noiseGain = gain * RadioNoise;
      gain *= 1.0 f - RadioNoise;
    }
  }
  VoipSound.SetPosition(position);
  VoipSound.Gain = gain;
  if (noiseGain > 0.0 f) {
    if (radioNoiseChannel == null || !radioNoiseChannel.IsPlaying) {
      radioNoiseChannel = SoundPlayer.PlaySound("radiostatic");
      radioNoiseChannel.Category = "voip";
      radioNoiseChannel.Looping = true;
    }
    radioNoiseChannel.Near = VoipSound.Near;
    radioNoiseChannel.Far = VoipSound.Far;
    radioNoiseChannel.Position = position;
    radioNoiseChannel.Gain = noiseGain;
  } else if (radioNoiseChannel != null) {
    radioNoiseChannel.Gain = 0.0 f;
  }
}