Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Audio stops after a few hundred consecutive calls  (Read 6202 times)

0 Members and 1 Guest are viewing this topic.

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
[SOLVED]Audio stops after a few hundred consecutive calls
« 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.
« Last Edit: August 06, 2013, 09:01:13 am by Antidote »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Audio stops after a few hundred consecutive calls
« Reply #1 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.
Laurent Gomila - SFML developer

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Audio stops after a few hundred consecutive calls
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Audio stops after a few hundred consecutive calls
« Reply #3 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
Laurent Gomila - SFML developer

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Audio stops after a few hundred consecutive calls
« Reply #4 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED]Audio stops after a few hundred consecutive calls
« Reply #5 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: [SOLVED]Audio stops after a few hundred consecutive calls
« Reply #6 on: January 11, 2014, 09:57:06 pm »
For my purposes RAII isn't the answer, otherwise I would use it.

Daddi

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
    • http://foxdev.de/
    • Email
Re: [SOLVED]Audio stops after a few hundred consecutive calls
« Reply #7 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 :)

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: [SOLVED]Audio stops after a few hundred consecutive calls
« Reply #8 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.
« Last Edit: January 11, 2014, 11:47:59 pm by Antidote »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED]Audio stops after a few hundred consecutive calls
« Reply #9 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 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: [SOLVED]Audio stops after a few hundred consecutive calls
« Reply #10 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.
« Last Edit: January 12, 2014, 10:13:45 pm by Antidote »

 

anything