SFML community forums

Help => Audio => Topic started by: Antidote on August 06, 2013, 02:49:50 am

Title: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Antidote on August 06, 2013, 02:49:50 am
I've been stress testing my engine for a few hours now and have about 1000 entities in one map that call the same sound when they are collided with by the player, after calling this sound about 400 to 500 times the whole sound backend dies with no error, just no sound, period.

Any ideas?

EDIT:
I know that this is a pretty extreme corner case, but I CAN see where this could become an issue down the line.
Title: Re: Audio stops after a few hundred consecutive calls
Post by: Laurent on August 06, 2013, 07:49:57 am
There's a maximum number of sounds (probably 512 on your machine), and if you don't properly release or reuse finished sounds then you won't be able to create new sounds once you reach this number.
Title: Re: Audio stops after a few hundred consecutive calls
Post by: Antidote on August 06, 2013, 08:23:58 am
Really? That makes sense, I'll modify my code to ensure it gets deleted, for some reason I was under the impression that SFML's resource manager handled that and using delete was a no no.

I'll just change it to a reference and have it free itself when it goes out of scope.
Title: Re: Audio stops after a few hundred consecutive calls
Post by: Laurent on August 06, 2013, 08:28:17 am
Quote
for some reason I was under the impression that SFML's resource manager handled that and using delete was a no no
There's no resource manager in SFML. And if you don't release your resources, SFML cannot magically do it for you :P
Title: Re: Audio stops after a few hundred consecutive calls
Post by: Antidote on August 06, 2013, 09:00:59 am
Ah so you're right, that's what i get for reading the source at 2AM XD
Anyway, thanks for the help. That was indeed the problem.
Title: Re: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Nexus on August 19, 2013, 10:28:40 pm
If you're using new -- or even worse, new[] -- then stop using it. Manual memory management is error-prone, replace it with RAII.

Simply take a STL container such as std::vector. To store sounds, a std::queue is quite useful, as you can pop the front elements as long as they've finished playing.
Title: Re: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Antidote on January 11, 2014, 09:57:06 pm
For my purposes RAII isn't the answer, otherwise I would use it.
Title: Re: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Daddi on January 11, 2014, 10:06:49 pm
Could you show us these purposes? I'm interested in cases where RAII can't or shouldn't be used :)
Title: Re: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Antidote on January 11, 2014, 11:42:10 pm
Implementing RAII in C isn't exactly the easiest thing to do ;P

I'm also attempting to port sfml-audio to wii using libogc, with moderate success, sfml-system still has a long way to go, and sfml-window is non-existent right now.
Title: Re: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Nexus on January 12, 2014, 02:50:25 pm
Next time, tell us you're using C from the beginning ;)

For C, there are also libraries (http://stackoverflow.com/questions/305611/container-class-library-for-c) for containers and data structures, even if they're more cumbersome to use than in C++. I don't know if those dependencies are okay for your project, but they might be interesting nevertheless.
Title: Re: [SOLVED]Audio stops after a few hundred consecutive calls
Post by: Antidote on January 12, 2014, 10:11:10 pm
It all depends on the memory footprint. But usually containers on the Wii aren't a bad idea so I'll definitely look into it.

The nice thing about libogc, is that it implements semaphores in the threading module, which will makes things a little less painful.