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

Bugfix: don't play theme if music off #42

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docs/docs/reference/externals/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## <a href="#bassmusic_play">BassMusic_Play</a>

Triggers an event to start a new music theme.
Triggers an event to start a new music theme. If the player has turned off the music in the menu, the theme will not be played.

```dae
func void BassMusic_Play(var string id)
Expand Down
5 changes: 5 additions & 0 deletions src/Gothic/Externals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace GOTHIC_NAMESPACE
{
int BassMusic_Play()
{
if (s_musicSystemDisabled)
Copy link
Member

Choose a reason for hiding this comment

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

Compilation error

D:\a\zBassMusic\zBassMusic\src\Gothic/Externals.hpp(9): error C2065: 's_musicSystemDisabled': undeclared identifier
D:\a\zBassMusic\zBassMusic\src\Gothic/Externals.hpp(9): error C2065: 's_musicSystemDisabled': undeclared identifier
D:\a\zBassMusic\zBassMusic\src\Gothic/Externals.hpp(9): error C2065: 's_musicSystemDisabled': undeclared identifier
D:\a\zBassMusic\zBassMusic\src\Gothic/Externals.hpp(9): error C2065: 's_musicSystemDisabled': undeclared identifier

Copy link
Member

@piotrmacha piotrmacha Jul 3, 2024

Choose a reason for hiding this comment

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

@damianut, please make the following changes:

  1. Replace s_musicSystemDisabled with zCMusicSystem::s_musicSystemDisabled - this symbol is a static member of zCMusicSystem class, but in external we are outside the class context.
  2. Move your if below parser->GetParameter(id); - in externals, we must always pop every parameter from the stack before early return. Otherwise, it would lead to memory leaks or even a crash.

The final code should look like

    int BassMusic_Play()
    {
        zSTRING id;
        parser->GetParameter(id);
        if (zCMusicSystem::s_musicSystemDisabled)
        {
            log->Error("Music system disabled.");
            return 0;
        }
        zCMusicTheme* theme = zmusic->LoadThemeByScript(id);
        zmusic->PlayTheme(theme, zMUS_THEME_VOL_DEFAULT, zMUS_TR_DEFAULT, zMUS_TRSUB_DEFAULT);
        return 0;
    }

{
log->Error("Music system disabled.");
return 0;
}
zSTRING id;
parser->GetParameter(id);
zCMusicTheme* theme = zmusic->LoadThemeByScript(id);
Expand Down
Loading