Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AL lib throws unclosed device warning on proper game exit #8247

Open
2 tasks done
Dominav opened this issue Mar 18, 2024 · 4 comments
Open
2 tasks done

AL lib throws unclosed device warning on proper game exit #8247

Dominav opened this issue Mar 18, 2024 · 4 comments
Milestone

Comments

@Dominav
Copy link

Dominav commented Mar 18, 2024

Prerequisites

  • I have verified this issue is present in the develop branch
  • I have searched open and closed issues to ensure it has not already been reported.

MonoGame Version

MonoGame 3.8.1.303

Which MonoGame platform are you using?

MonoGame Cross-Platform Desktop Application (mgdesktopgl)

Operating System

Windows 10 Pro 22H2

Description

The game doesn't properly dispose of audio somewhere on proper game exit, and it results in a AL lib warning and a possible (?) memory leak.

Steps to Reproduce

  1. Create a blank mgdesktopgl template project
  2. Load Song instance using Content Builder and Content.Load<Song>()
  3. Call MediaPlayer.Play(song instance)
  4. Close the game either through the red cross or pressing Esc

Minimal Example Repo

No response

Expected Behavior

The warning should not appear?

Resulting Behavior

The folowing warning is thrown in the Output console in VSCode:
"AL lib: (EE) alc_cleanup: 1 device not closed"

Files

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace audio_issue;

public class Game1 : Game
{
    private GraphicsDeviceManager _graphics;
    private SpriteBatch _spriteBatch;
    private Song song;

    public Game1()
    {
        _graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        IsMouseVisible = true;
    }

    protected override void Initialize()
    {
        base.Initialize();
    }

    protected override void LoadContent()
    {
        _spriteBatch = new SpriteBatch(GraphicsDevice);
        song = Content.Load<Song>("Divider");
        MediaPlayer.Play(song);
        soundEffect.Play();
    }

    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            Exit();
        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        base.Draw(gameTime);
    }
}
@mrhelmut
Copy link
Contributor

We're going to drop using OpenAL entirely in the near future, so that's a non-concern.

@Dominav
Copy link
Author

Dominav commented Mar 19, 2024

We're going to drop using OpenAL entirely in the near future, so that's a non-concern.

@mrhelmut Okay, thanks for reply! Have a great day :)

@Mindfulplays
Copy link
Contributor

Adding some notes as I encountered this too (requires some surgical fixes - so may not be worth the effort - let process cleanup clean this with a silent harmless logging):
Song (NVorbis impl) uses both the static OpenALSoundController.EnsureInitialized and the non-static methods via the stream (OggStream). This makes it nearly impossible to cleanly call OpenALSoundController.DestroyInstance -> as there may be streams that are not disposed but holding onto the OpenALSoundController.

So we need to destroy all streams first and then destroy the sound controller - hard to achieve with the current design (mixing statc/non-static).

Curious, what's the alternative to OpenAL? SDL_Audio?

@mrhelmut
Copy link
Contributor

Curious, what's the alternative to OpenAL? SDL_Audio?

FAudio. It's a reimplementation of XAudio 2 that is 100% accurate to XNA, so it's a no brainer.

@mrhelmut mrhelmut added this to the 3.9.0 milestone Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants