HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

SimError's memory leak (help me)

01-08-2004, 06:48 PM#1
Vexorian
Code:
function SimError takes player ForPlayer, string msg returns nothing
    local sound error = CreateSound( "Sound\\Interface\\Error.wav", false, false, false, 10, 10, "HeroAcksEAX" )
    if (GetLocalPlayer() == ForPlayer) then
       call ClearTextMessages()
       call DisplayTimedTextToPlayer( ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r" )
       call SetSoundParamsFromLabel( error, "InterfaceError" )
       call SetSoundDuration( error, 614 )
       call SetSoundChannel( error, 6 )
       call PlaySoundBJ( error )
    endif
endfunction

That was the SimError function I found in weaaddar's Amazing item system, Looked silly and there was an obvius issue with it, specially because I didn't took a seriuos look at it since the day I made it.

The thing is that it starts with a CreateSound() unfortunnally sounds are handles too and creating a sound everytime this function runs was a bad idea, I started testing the function in a blank map and it leaked, so if you don't want links in maps that use that function:

1 Create a sound variable at the sound editor and use

Code:
function SimError takes player ForPlayer, string msg returns nothing
    if (GetLocalPlayer() == ForPlayer) then
       call ClearTextMessages()
       call DisplayTimedTextToPlayer( ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r" )
       call StartSound( gg_snd_error )
    endif
endfunction

Or help me making a non leaking SimError function, this is what I got at the moment:

Code:
function SimError takes player ForPlayer, string msg returns nothing
 local sound error = CreateSound( "Sound\\Interface\\Error.wav", false, false, false, 10, 10, "InterfaceError" )
    if (GetLocalPlayer() == ForPlayer) then
        call ClearTextMessages()
        call DisplayTimedTextFromPlayer( ForPlayer, 0.515, 0, 2, "|cffffcc00"+msg+"|r" )
        call StartSound( error )
        call KillSoundWhenDone( error)
    endif
 set error=null
endfunction

It works and doesn't leak, but I fear that it may desync (haven't tested it online)
01-08-2004, 08:14 PM#2
AIAndy
It will likely desync and even if it does not it will leak for all but ForPlayer.
What you could do is wait GetSoundDuration + some time and then kill the sound for both players.
Or you could actually play the sound for both players but set the volume of the sound to 0 for one player (not sure if that will desync).
01-11-2004, 07:43 PM#3
Vexorian
Did you actually test it?

Anyways I am starting to think at a sound editor made variable is the best solution
01-27-2004, 09:05 PM#4
weaaddar
Have you found a solution to this problem?
01-28-2004, 01:47 AM#5
dataangel
This is easy to fix. Declare the sound variable local at the top like you do, but don't set it equal to CreateSound until you're in the GetLocalPlayer() block. Then it shouldn't leak or desync.
01-28-2004, 01:21 PM#6
Vexorian
I always thought that creating any handle type for the local player would desync.

I temporary can't test it because my comp's power supply is out of game
01-28-2004, 02:00 PM#7
weaaddar
your suggestion Data causes a desync.
01-30-2004, 03:02 PM#8
Vexorian
I thought that using game cache to save the sound variable the time it is created and loading the value on the game cache the next times would help


But it would make SimError to need H2I , I2Sound and to use game cache #|
01-30-2004, 08:13 PM#9
KaTTaNa
This might work (I havn't tested).
Code:
function SimError takes player ForPlayer, string msg returns nothing
    local sound error = CreateSound( "Sound\\Interface\\Error.wav", false, false, false, 10, 10, "HeroAcksEAX" )
    if (GetLocalPlayer() == ForPlayer) then
       call SetSoundVolume(error, 100)
       call ClearTextMessages()
       call DisplayTimedTextToPlayer( ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r" )
    else
       call SetSoundVolume(error, 0)
    endif
    call SetSoundParamsFromLabel( error, "InterfaceError" )
    call SetSoundDuration( error, 614 )
    call SetSoundChannel( error, 6 )
    call PlaySoundBJ( error )
    call KillSoundWhenDone(error)
    set error=null
endfunction