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

Fix deadlock inside BASS library finalization. #223

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cleo_plugins/Audio/CSoundSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CLEO_Utils.h"
#include "CAEAudioHardware.h"
#include "CCamera.h"
#include <thread>

namespace CLEO
{
Expand Down Expand Up @@ -52,7 +53,7 @@ namespace CLEO
if (initialized)
{
TRACE("Freeing BASS library");
BASS_Free();
std::thread(BASS_Free);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a deadlock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library internally waits to some (COM?) objects to be finalized. BASS author says free can not be called in dll main. I tried to do it from some other callback like on game closing, but with same results. Other author suggestion is not to call free at all and let it be released automatically, but that makes game crashing (I guess due all ModLoader hacks).

Calling it from another thread works. It is visible in log that CLEO proceeded with other cleanup steps, game aslo closes without problems.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I would also remove free and let OS handle the unloading.

Is the crash reproducible 100%? Does it depend on other plugins installed in game?

Copy link
Collaborator Author

@MiranDMC MiranDMC Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like all you need is ModLoader. BASS_Free changing has some results in web search.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it wasn't an issue in CLEO4?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea. ModLoader is thin ice. In CLEO4 Bass was managed by core.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm seems to be working without calling free at all. I have no idea why game was crashing for me when testing it previously.

initialized = false;
}
TRACE("SoundSystem finalized");
Expand Down