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

Fixed "Memory leak and crash when falling asleep with a radio on #32968" #33297

Merged
merged 5 commits into from
Aug 21, 2019

Conversation

ipcyborg
Copy link
Contributor

@ipcyborg ipcyborg commented Aug 17, 2019

Summary

SUMMARY: Bugfixes "Memory leak and crash when falling asleep with a radio on #32968"

Purpose of change

Fixes #32968

Describe the solution

Fixed by checking if the radio channel (number 21) is already playing something.
Assumed that a single channel should not be spammed with more sound.
UPDATE: found Channel assignments in sfx::do_ambient.

Describe alternatives you've considered

Check other usage of this channel.
Check other channels too.
Check sdlsound.cpp: if the memory allocated for a sound is always released?

Additional context

UPDATE:
Allocating memory in do_pitch_shift, using in:
play_variant_sound
play_variant_sound_pitch
play_ambient_variant_sound

Should be freed after the channel is finished.

play_ambient_variant_sound is relatively safe, since it has a channel parameter. So this channel could be checked before playing the sound.
The other two functions has angle, but not channel. So the sound will be played on first available channel.

Suggestion:

  1. Add channel to two other functions.
  2. Check every channel before playing a sound inside of these functions. Avoid sound spamming.

@ipcyborg ipcyborg changed the title Fixed "Memory leak and crash when falling asleep with a radio on #32968" [WIP] [CR] Fixed "Memory leak and crash when falling asleep with a radio on #32968" Aug 17, 2019
@ZhilkinSerg
Copy link
Contributor

Maybe we should make channel enum to get rid of all these magic numbers?

@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` SDL: Tiles / Sound Tiles visual interface and sounds. Sound Events Sound events handling in the game labels Aug 17, 2019
Moved `outdoor_blizzard` closer to other `outdoor` sounds.
Added missing check for "Outdoor blizzard" in `sfx::do_ambient`.
Added check "is channel playing" inside of `play_ambient_variant_sound`. May not be necessary, leads to double checks. Just to be sure?
Fixed playing `radio`/`chatter` as `play_ambient_variant_sound`.
…annel).

Reordered `danger` channels.
Fixed `init_sound` groups assignment.
Avoid pitching a sound when it is not required: like when only angle is set, but no pitch.
Changed default pitch to -1.0 (as `not pitch`). Probably make steps for pitch and cache picthed sound effects for optimization?.
Added error handling in `play sound` functions.
Added loops parameter to `play_ambient_variant_sound` function.
Added `stop_sound_effect_timed` to stop sound effect after a given time.
Altered active radio "choose what to play" algorithm. Some chance to play static or chatter, but only once (should not be annoying).
@ipcyborg
Copy link
Contributor Author

UPDATE:

Added enums for channels & groups of sound effects.
Moved outdoor_blizzard closer to other outdoor sounds.
Added missing check for "Outdoor blizzard" in sfx::do_ambient.
Added check "is channel playing" inside of play_ambient_variant_sound. May not be necessary, leads to double checks. Just to be sure?
Fixed playing radio/chatter as play_ambient_variant_sound.
Added separate channel for radio (instead of using player activity channel).
Reordered danger channels.
Fixed init_sound groups assignment.
Avoid pitching a sound when it is not required: like when only angle is set, but no pitch.
Changed default pitch to -1.0 (as not pitched). Probably make steps for pitch and cache pitched sound effects for optimization?.
Added error handling in play sound functions.
Added loops parameter to play_ambient_variant_sound function.
Added stop_sound_effect_timed to stop sound effect after a given time.
Altered active radio "choose what to play" algorithm. Some chance to play static or chatter, but only once (should not be annoying).

@ipcyborg ipcyborg changed the title [WIP] [CR] Fixed "Memory leak and crash when falling asleep with a radio on #32968" Fixed "Memory leak and crash when falling asleep with a radio on #32968" Aug 20, 2019
@ipcyborg ipcyborg changed the title Fixed "Memory leak and crash when falling asleep with a radio on #32968" [WIP] Fixed "Memory leak and crash when falling asleep with a radio on #32968" Aug 20, 2019
@ipcyborg
Copy link
Contributor Author

ipcyborg commented Aug 20, 2019

Found an issue with "@" soundpack on my system:

"type": "sound_effect",
"id" : "environment",
"variant" : "daytime",
"volume" : 85,
"files" : [
        "env/ambience_and_weather/daytime_1.ogg",
        "env/ambience_and_weather/daytime_2.ogg",
        "env/ambience_and_weather/daytime_2.mp3"
]

The last file daytime_2.mp3 now gives the following error when played:
sdlsound.cpp:543: Failed to play sound effect: Tried to play a chunk with a bad frame
This file is missing in the soundpack.
But also looks like this format (mp3) could not be payed using SDL. Ogg files are ok.
The error just goes into log.
Should I remove the error logging from play_ambient_variant_sound and other functions?

  • OS: Linux
    • OS Version: Distributor ID: Ubuntu; Description: Ubuntu 16.04.6 LTS; Release: 16.04; Codename: xenial;
  • Game Version: 0.D-6617-gf7415e1 [64-bit]
  • Graphics Version: Tiles
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food]
    ]

Probably related:
https://sites.google.com/site/sdlgamer/beginner/lesson-12
Some specific lib is required: smpeg.dll 192k (For mp3 format music file).
Or just SDL2.

@ipcyborg ipcyborg changed the title [WIP] Fixed "Memory leak and crash when falling asleep with a radio on #32968" Fixed "Memory leak and crash when falling asleep with a radio on #32968" Aug 20, 2019
@kevingranade kevingranade merged commit 94aac50 into CleverRaven:master Aug 21, 2019
@ipcyborg ipcyborg deleted the fix-32968-sound-mem-leak branch August 21, 2019 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` SDL: Tiles / Sound Tiles visual interface and sounds. Sound Events Sound events handling in the game
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAUSE FOUND] Memory leak and crash when falling asleep with a radio on
3 participants