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

Author Topic: Multiple Sounds problem | they don't play after time  (Read 1902 times)

0 Members and 1 Guest are viewing this topic.

Blodyavenger

  • Newbie
  • *
  • Posts: 2
    • View Profile
Multiple Sounds problem | they don't play after time
« on: April 21, 2013, 07:26:29 pm »
I've looked around the forum and I think there was no solution for my problem. So here it goes:

I have like 10 sounds playing at once like falling stones, water dripping, player steps, fire burning etc. I have this earthquake scene where stones are falling to the ground (each stone has it's own sf::Sound) and when it hits the ground, sound plays and then the object is destroyed. After time, I stop hearing stone sounds (not entirely, sound plays from time to time) and I'm not sure what I'm doing wrong.

  • I keep sound buffers in one array and I point sf::Sound to these
  • Objects with sound have static sf::Sound for member variable
  • Objects are allocated with new but I destroy them with delete

Is there a way to see how many sf::Sound instances are alive? Anything would help, thanks a lot!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
AW: Multiple Sounds problem | they don't play after time
« Reply #1 on: April 21, 2013, 07:55:37 pm »
There's no such function, but it should be fairly simple to track what exists and what not. I'd now guess, that you're prematuratily destroy the buffer or the sound object. Make sure they both exist as long as the sound plays.
Otherwise make sure you don't load a different buffer into a sound object while it's still playing another sound.

I strongly advise you against the usage of manaual memory management, instead you should read up on RAII and smart pointers. Also static objects are mostly a bad idea, since those are essentially globals. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Blodyavenger

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Multiple Sounds problem | they don't play after time
« Reply #2 on: April 21, 2013, 08:01:29 pm »
Ok, buffers are loaded once on the start and destroyed once at the end. So this shouldn't be the issue. What if I call STOP on sound just before I delete it, is that fine?

Many people suggested to use smart pointers already so maybe I really should as soon as I can.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Multiple Sounds problem | they don't play after time
« Reply #3 on: April 21, 2013, 08:10:02 pm »
http://en.sfml-dev.org/forums/index.php?topic=8402.msg56393#msg56393

You needn't stop sounds before destruction, that's the task of the destructor.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: