diff --git a/code/datums/sound_player.dm b/code/datums/sound_player.dm index 0e110e33625..d3952f54dce 100644 --- a/code/datums/sound_player.dm +++ b/code/datums/sound_player.dm @@ -142,7 +142,11 @@ GLOBAL_DATUM_INIT(sound_player, /singleton/sound_player, new) /datum/sound_token/Destroy() Stop() - . = ..() + source = null + if (listeners) + listeners.Cut() + sound = null + return ..() /datum/sound_token/proc/SetVolume(new_volume) new_volume = clamp(new_volume, 0, 100) diff --git a/code/modules/synthesized_instruments/instruments.dm b/code/modules/synthesized_instruments/instruments.dm index e8dd08986f6..21cb48386a8 100644 --- a/code/modules/synthesized_instruments/instruments.dm +++ b/code/modules/synthesized_instruments/instruments.dm @@ -5,6 +5,10 @@ var/list/samples = list() // Write here however many samples, follow this syntax: "%note num%"='%sample file%' eg. "27"='synthesizer/e2.ogg'. Key must never be lower than 0 and higher than 127 var/list/datum/sample_pair/sample_map = list() // Used to modulate sounds, don't fill yourself +/datum/instrument/Destroy() + samples.Cut() + QDEL_LIST_ASSOC_VAL(sample_map) + return ..() /datum/instrument/proc/create_full_sample_deviation_map() // Obtain samples diff --git a/code/modules/synthesized_instruments/real_instruments.dm b/code/modules/synthesized_instruments/real_instruments.dm index a0f0dde1dd3..76e7b833854 100644 --- a/code/modules/synthesized_instruments/real_instruments.dm +++ b/code/modules/synthesized_instruments/real_instruments.dm @@ -203,8 +203,17 @@ /datum/real_instrument/Destroy() + if (islist(instruments)) + var/list/aslist = instruments + QDEL_LIST_ASSOC_VAL(aslist) + else + QDEL_NULL(instruments) QDEL_NULL(player) + QDEL_NULL(song_editor) + QDEL_NULL(usage_info) owner = null + QDEL_NULL(env_editor) + QDEL_NULL(echo_editor) return ..() /obj/structure/synthesized_instrument @@ -225,14 +234,9 @@ src.real_instrument = new /datum/real_instrument(src, new sound_player(src, instruments[pick(instruments)]), instruments) /obj/structure/synthesized_instrument/Destroy() - QDEL_NULL(src.real_instrument) - if (islist(instruments)) - var/list/as_list = instruments - for (var/key in as_list) - qdel(as_list[key]) - instruments = null - . = ..() - + QDEL_NULL(real_instrument) + QDEL_LIST(instruments) + return ..() /obj/structure/synthesized_instrument/attack_hand(mob/user) src.interact(user) diff --git a/code/modules/synthesized_instruments/song.dm b/code/modules/synthesized_instruments/song.dm index 05b97baa85e..14ec0c6ddcb 100644 --- a/code/modules/synthesized_instruments/song.dm +++ b/code/modules/synthesized_instruments/song.dm @@ -31,7 +31,10 @@ available_channels = GLOB.musical_config.channels_per_instrument /datum/synthesized_song/Destroy() + playing = null player.event_manager.deactivate() + player = null + instrument_data = null return ..() /datum/synthesized_song/proc/sanitize_tempo(new_tempo) // Identical to datum/song diff --git a/code/modules/synthesized_instruments/sound_player.dm b/code/modules/synthesized_instruments/sound_player.dm index 6eb5afe5502..8dd0cd4ae32 100644 --- a/code/modules/synthesized_instruments/sound_player.dm +++ b/code/modules/synthesized_instruments/sound_player.dm @@ -28,12 +28,11 @@ GLOB.instrument_synchronizer.register_global(src, .proc/check_wait) /datum/sound_player/Destroy() - src.song.playing = FALSE - src.actual_instrument = null - src.instrument = null + actual_instrument = null + instrument = null QDEL_NULL(song) QDEL_NULL(event_manager) - tokens = null + QDEL_LIST(tokens) GLOB.instrument_synchronizer.unregister_global(src, .proc/check_wait) wait = null . = ..() @@ -59,7 +58,7 @@ /datum/sound_player/proc/unsubscribe(datum/sound_token/instrument/oldtoken) if(!istype(oldtoken)) CRASH("Non token type passed to unsubscribe function.") - tokens -= oldtoken + tokens.Remove(oldtoken) /datum/sound_player/proc/apply_modifications(sound/what, note_num, which_line, which_note) // You don't need to override this diff --git a/code/modules/synthesized_instruments/sound_token.dm b/code/modules/synthesized_instruments/sound_token.dm index dd5201f2481..02d0b88bb16 100644 --- a/code/modules/synthesized_instruments/sound_token.dm +++ b/code/modules/synthesized_instruments/sound_token.dm @@ -49,8 +49,8 @@ /datum/sound_token/instrument/Stop() if(player) player.unsubscribe(src) + player = null . = ..() /datum/sound_token/instrument/Destroy() - player = null return ..() diff --git a/html/changelogs/hellfirejag-instrument-shit-again.yml b/html/changelogs/hellfirejag-instrument-shit-again.yml new file mode 100644 index 00000000000..2d1b6527694 --- /dev/null +++ b/html/changelogs/hellfirejag-instrument-shit-again.yml @@ -0,0 +1,12 @@ +author: Hellfirejag + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Made a 2nd attempt to fix the instruments memory leak."