Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kweepa on Thu 06/05/2010 20:08:00

Title: Memory leak with sound?
Post by: Kweepa on Thu 06/05/2010 20:08:00
My game keeps using more and more memory (the private working set in Task Manager), unless I disable sound from winsetup.
Is this a known bug or a problem with my machine or scripting?
Thanks!

Steve

[EDIT] This is with 3.2.0.102 (Final4)
Title: Re: Memory leak with sound?
Post by: Alan v.Drake on Thu 06/05/2010 21:54:17
Confirmed for memory leak.
Even the earlier 3.2.0.102 (Final 3) seems to have the same problem.

- Alan



Title: Re: Memory leak with sound?
Post by: xenogia on Thu 06/05/2010 22:02:51
Which could definetly give a reason to why there is sound stutters.
Title: Re: Memory leak with sound?
Post by: Dualnames on Thu 06/05/2010 22:04:30
Quote from: Xenogia on Thu 06/05/2010 22:02:51
Which could definetly give a reason to why there is sound stutters.

Which has been there since 2.72. I never kind of noticed the memory leak ever. :-\
Title: Re: Memory leak with sound?
Post by: Kweepa on Thu 06/05/2010 22:16:37
Quote from: Xenogia on Thu 06/05/2010 22:02:51
Which could definetly give a reason to why there is sound stutters.
Let's not jump to conclusions!
These are probably unrelated.
Title: Re: Memory leak with sound?
Post by: Alan v.Drake on Thu 06/05/2010 23:03:52
Yeah, the stutter usually happens those times the audio buffer isn't being cleared when the engine isn't fast enough to fill it... uhm, isn't audio playback handled in a different thread to avoid this ?
Title: Re: Memory leak with sound?
Post by: Wyz on Thu 06/05/2010 23:12:22
Technically a buffer should never cause memory leaks. A buffer is a preallocated space in the memory and when they overflow they cause segmentation errors and not leaks. I'm afraid the problem is a bit more complicated.
What kind of sound files(file format, version etc) are you using?
Title: Re: Memory leak with sound?
Post by: xenogia on Fri 07/05/2010 00:10:40
It is all good CJ is looking into the sound stutters anyhow.. and if you want to know I'm using OGG and the latest build of ags.
Title: Re: Memory leak with sound?
Post by: Pumaman on Sun 09/05/2010 16:53:18
Quote from: SteveMcCrea on Thu 06/05/2010 20:08:00
My game keeps using more and more memory (the private working set in Task Manager), unless I disable sound from winsetup.

Thanks for reporting this. I think I have identified the cause of the problem; could you please download this patched ACWIN.EXE and replace the one in your AGS folder with it. Then, see if you still get the memory leak:
http://www.adventuregamestudio.co.uk/acwin.zip
Title: Re: Memory leak with sound?
Post by: Alan v.Drake on Sun 09/05/2010 17:13:23
Quote from: Pumaman on Sun 09/05/2010 16:53:18
Quote from: SteveMcCrea on Thu 06/05/2010 20:08:00
My game keeps using more and more memory (the private working set in Task Manager), unless I disable sound from winsetup.

Thanks for reporting this. I think I have identified the cause of the problem; could you please download this patched ACWIN.EXE and replace the one in your AGS folder with it. Then, see if you still get the memory leak:
http://www.adventuregamestudio.co.uk/acwin.zip


It seems to work just fine, I havent noticed any leak with it.

- Alan
Title: Re: Memory leak with sound?
Post by: Kweepa on Sun 09/05/2010 18:20:23
That seems to have done it - thanks Chris!
Memory keeps growing until all effects have played once (I guess that's what's happening), then it stops.
Steve

PS Is it safe to distribute a game with this acwin compiled in?
Title: Re: Memory leak with sound?
Post by: xenogia on Mon 10/05/2010 03:18:44
Might as well add this to my game as well, as after people pointing this out I did notice the memory leak.
Mine went up to 300mb use .. ouch
Title: Re: Memory leak with sound?
Post by: Alan v.Drake on Mon 10/05/2010 09:16:10
Hmm... on further testing with "No Digital Sound", there are now null pointer exceptions when audio is .Play()ed... but not always...

EDIT: I realized the error comes when trying to access the channel returned by the .Play() function, the same things happens also with sounds enabled, while skipping a cutscene that contains a code such as follows:

StartCutscene(eSkipESCOrRightButton);
player.Walk(320, 140, eBlock);
Wait(40);
Wait(40);
AudioChannel *channel = aDoorClose.Play();
channel.Panning = 100;
EndCutscene();

it says that "channel" is null, and it is. I can work around the problem with a "if (channel!=null) ..." .
Hope that helps fix the problem.

- Alan
Title: Re: Memory leak with sound?
Post by: EnterTheStory (aka tolworthy) on Thu 13/05/2010 08:39:07
Quote from: Pumaman on Sun 09/05/2010 16:53:18please download this patched ACWIN.EXE and replace the one in your AGS folder with it. Then, see if you still get the memory leak:
http://www.adventuregamestudio.co.uk/acwin.zip

Should this be downloaded for all versions of 3.x? (Or maybe that's a really stupid question)
Title: Re: Memory leak with sound?
Post by: Kweepa on Thu 13/05/2010 18:18:32
Quote from: Alan v.Drake on Mon 10/05/2010 09:16:10
EDIT: I realized the error comes when trying to access the channel returned by the .Play() function, the same things happens also with sounds enabled
<snip>
it says that "channel" is null, and it is. I can work around the problem with a "if (channel!=null) ..." .
I would imagine this happened before the patch, as you should always check that the returned channel is not null.
But given how likely this is to happen, it seems like AGS should return a dummy channel which can be queried to determine if the sound actually played.
Title: Re: Memory leak with sound?
Post by: Codex on Sat 15/05/2010 23:34:01
I just wanted to report that the .exe replace fixed a major stuttering problem with my audio.

Thanks!
Title: Re: Memory leak with sound?
Post by: xenogia on Sat 15/05/2010 23:36:15
Codex that has been there for ages I'm afraid.
Title: Re: Memory leak with sound?
Post by: Codex on Sun 16/05/2010 00:43:01
Well, it must have been just upgrading to 3.2 then, thanks!
Title: Re: Memory leak with sound?
Post by: Pumaman on Mon 31/05/2010 18:58:31
QuoteThat seems to have done it - thanks Chris!
Memory keeps growing until all effects have played once (I guess that's what's happening), then it stops.

PS Is it safe to distribute a game with this acwin compiled in

Glad to hear it! It should be safe to use that EXE, it is just Final 4 with that extra fix.
I'll roll it into the next release.

QuoteEDIT: I realized the error comes when trying to access the channel returned by the .Play() function, the same things happens also with sounds enabled, while skipping a cutscene that contains a code such as follows:

Yes, the value returned from Play() should always be checked to see if it is null. However, I do see Steve's point that this could be a major headache and maybe returning a dummy channel would be better.

QuoteShould this be downloaded for all versions of 3.x? (Or maybe that's a really stupid question)

No, it only affects 3.2. If you're using an earlier version, you don't need it.