Ok, so I've been posting my problems on
this thread, which I previously believed were due to networking errors. After further investigation, I realized that the problem is rooted in the sound devices.
I've reinstalled openAL using the libraries provided with SFML, so it's not that.
Here is what Very Sleepy presents me:
If you look at the right hand side on the callstack, it appears that it freezes while playing sounds Here is another snapshot I took:
With this callstack freeze, it appears that it is trying to create a sound instead. Very odd.
Here is my SoundHandler.hpp
#ifndef __SOUNDHANDLER_HPP__
#define __SOUNDHANDLER_HPP__
#include "SFML/System.hpp"
#include "SFML/Audio.hpp"
#include <vector>
class SoundHandler
{
private:
sf::Clock timer;
//////////////////////////
// Sounds //
//////////////////////////
sf::SoundBuffer clickBuffer;
sf::Sound clickSFX;
sf::SoundBuffer chopBuffer;
sf::Sound chopSFX;
sf::SoundBuffer leavesBuffer;
sf::Sound leavesSFX;
sf::SoundBuffer windBuffer;
sf::Sound windSFX;
sf::SoundBuffer stormBuffer;
sf::Sound stormSFX;
sf::SoundBuffer rockBuffer;
sf::Sound rockSFX;
sf::Music deathSFX;
sf::SoundBuffer blood1Buffer;
sf::Sound blood1SFX;
sf::Music birdSFX;
sf::SoundBuffer killBuffer;
sf::Sound killSFX;
sf::SoundBuffer popBuffer;
sf::Sound popSFX;
sf::SoundBuffer splatBuffer;
sf::Sound splatSFX;
sf::SoundBuffer chargeBuffer;
sf::Sound chargeSFX;
sf::SoundBuffer splashBuffer;
sf::Sound splashSFX;
sf::SoundBuffer waterBuffer;
sf::Sound waterSFX;
sf::SoundBuffer fireBuffer;
sf::Sound fireSFX;
sf::Music cricketsSFX;
sf::Music musicboxSFX;
sf::Music combatSFX;
sf::SoundBuffer typeBuffer;
sf::Sound typeSFX;
sf::Music feetSFX;
sf::SoundBuffer puffBuffer;
sf::Sound puffSFX;
sf::SoundBuffer stabBuffer;
sf::Sound stabSFX;
//////////////////////////
// Music //
//////////////////////////
std::vector<sf::Int32> playlist;
sf::Int32 playNumber;
sf::Music ambient1;
sf::Music ambient2;
sf::Music ambient3;
sf::Music ourHome;
sf::Music fishing;
sf::Music intro;
sf::Music night;
sf::Music main;
bool firstPlayed;
// Other vars
bool soundMuted;
bool musicMuted;
public:
SoundHandler();
void load();
void handleMusic();
void stopMusic();
bool musicOn;
void muteMusic();
void muteSound();
bool playClick();
void stopClick();
bool playWind();
void stopWind();
bool playChop();
void stopChop();
bool playLeaves();
void stopLeaves();
bool playStorm();
void stopStorm();
bool playRock();
void stopRock();
bool playDeath();
void stopDeath();
bool playBlood1();
void stopBlood1();
bool playBirds();
void stopBirds();
bool playKill();
void stopKill();
bool playPop();
void stopPop();
bool playSplat();
void stopSplat();
void playCharge();
void resetCharge();
void playFishing();
void stopFishing();
void playSplash();
void playWater();
void playCrickets();
void stopCrickets();
void playMain();
void playNight();
void playFire();
void playMusicbox();
void stopMusicbox();
void playCombat();
void playType();
void playFeet();
void playPuff();
void playStab();
};
#endif
...and my SoundHandler.cpp
#include "stdafx.h"
#include <random>
#include <time.h>
#include "SoundHandler.hpp"
#include "Globals.hpp"
SoundHandler::SoundHandler()
{
load();
musicMuted = false;
soundMuted = false;
}
void SoundHandler::load()
{
//////////////////////////
// Sounds //
//////////////////////////
clickBuffer.loadFromFile("rsc/SFX/click.ogg");
clickSFX.setBuffer(clickBuffer);
chopBuffer.loadFromFile("rsc/SFX/chop.ogg");
chopSFX.setBuffer(chopBuffer);
leavesBuffer.loadFromFile("rsc/SFX/leaves.ogg");
leavesSFX.setBuffer(leavesBuffer);
windBuffer.loadFromFile("rsc/SFX/wind.ogg");
windSFX.setBuffer(windBuffer);
windSFX.setLoop(true);
stormBuffer.loadFromFile("rsc/SFX/storm.ogg");
stormSFX.setBuffer(stormBuffer);
rockBuffer.loadFromFile("rsc/SFX/rock.ogg");
rockSFX.setBuffer(rockBuffer);
deathSFX.openFromFile("rsc/SFX/death.ogg");
blood1Buffer.loadFromFile("rsc/SFX/blood1.ogg");
blood1SFX.setBuffer(blood1Buffer);
birdSFX.openFromFile("rsc/SFX/birds.ogg");
killBuffer.loadFromFile("rsc/SFX/kill.ogg");
killSFX.setBuffer(killBuffer);
popBuffer.loadFromFile("rsc/SFX/pop.ogg");
popSFX.setBuffer(popBuffer);
splatBuffer.loadFromFile("rsc/SFX/splat.ogg");
splatSFX.setBuffer(splatBuffer);
chargeBuffer.loadFromFile("rsc/SFX/charge.ogg");
chargeSFX.setBuffer(chargeBuffer);
resetCharge();
splashBuffer.loadFromFile("rsc/SFX/splash.ogg");
splashSFX.setBuffer(splashBuffer);
waterBuffer.loadFromFile("rsc/SFX/water.ogg");
waterSFX.setBuffer(waterBuffer);
waterSFX.setVolume(25);
cricketsSFX.openFromFile("rsc/SFX/crickets.ogg");
fireBuffer.loadFromFile("rsc/SFX/fire.ogg");
fireSFX.setBuffer(fireBuffer);
musicboxSFX.openFromFile("rsc/SFX/musicbox.ogg");
musicboxSFX.setLoop(true);
combatSFX.openFromFile("rsc/SFX/combat.ogg");
typeBuffer.loadFromFile("rsc/SFX/type.ogg");
typeSFX.setBuffer(typeBuffer);
feetSFX.openFromFile("rsc/SFX/feet.ogg");
puffBuffer.loadFromFile("rsc/SFX/puff.ogg");
puffSFX.setBuffer(puffBuffer);
stabBuffer.loadFromFile("rsc/SFX/stab.ogg");
stabSFX.setBuffer(stabBuffer);
//////////////////////////
// Music //
//////////////////////////
// Day Playlist
ourHome.openFromFile("rsc/Music/ourHome.ogg"); // 0
playlist.push_back(0);
ambient1.openFromFile("rsc/Music/ambience1.ogg"); // 1
playlist.push_back(1);
ambient2.openFromFile("rsc/Music/ambience2.ogg"); // 2
playlist.push_back(2);
night.openFromFile("rsc/Music/night.ogg"); // 3
playlist.push_back(3);
ambient3.openFromFile("rsc/Music/ambience3.ogg"); // 4
playlist.push_back(4);
musicOn = true;
firstPlayed = false;
srand(time(NULL));
std::random_shuffle(playlist.begin(), playlist.end());
playNumber = 0;
// Fishing
fishing.openFromFile("rsc/Music/fishing.ogg");
fishing.setLoop(true);
// Intro
intro.openFromFile("rsc/Music/intro.ogg");
intro.setLoop(true);
// Main
main.openFromFile("rsc/Music/The Colony.ogg");
main.setLoop(true);
}
void SoundHandler::handleMusic()
{
if(((timer.getElapsedTime().asSeconds() >= 300) || ((!firstPlayed) && (timer.getElapsedTime().asSeconds() >= 60))) && musicOn && !musicMuted)
{
firstPlayed = true;
sf::Int32 songNumber = playlist[playNumber];
bool restartTimer = true;
if(songNumber == 0)
{
ourHome.play();
}
else if(songNumber == 1)
{
ambient1.play();
}
else if(songNumber == 2)
{
ambient2.play();
}
else if((songNumber == 3))
{
if((gl::Vars::timeOfDay == NIGHT) || (gl::Vars::timeOfDay == DAWN) || (gl::Vars::timeOfDay == DAWN))
night.play();
else
restartTimer = false;
}
else if((songNumber == 4))
{
ambient3.play();
}
if(restartTimer)
timer.restart();
playNumber++;
if(playNumber >= playlist.size())
{
srand(time(NULL));
std::random_shuffle(playlist.begin(), playlist.end());
playNumber = 0;
}
}
else if(timer.getElapsedTime().asSeconds() >= 300)
{
timer.restart();
}
}
void SoundHandler::stopMusic()
{
ourHome.stop();
ambient1.stop();
ambient2.stop();
ambient3.stop();
fishing.stop();
intro.stop();
night.stop();
musicboxSFX.stop();
main.stop();
}
void SoundHandler::muteMusic()
{
musicMuted = !musicMuted;
if(!musicMuted)
stopMusic();
}
void SoundHandler::muteSound()
{
soundMuted = !soundMuted;
windSFX.stop();
feetSFX.stop();
cricketsSFX.stop();
birdSFX.stop();
}
bool SoundHandler::playChop()
{
if(!soundMuted)
chopSFX.play();
return true;
}
void SoundHandler::stopChop()
{
chopSFX.stop();
}
bool SoundHandler::playClick()
{
if(!soundMuted)
clickSFX.play();
return true;
}
void SoundHandler::stopClick()
{
clickSFX.stop();
}
bool SoundHandler::playLeaves()
{
if(!soundMuted)
leavesSFX.play();
return true;
}
void SoundHandler::stopLeaves()
{
leavesSFX.stop();
}
bool SoundHandler::playWind()
{
if(!soundMuted)
windSFX.play();
return true;
}
void SoundHandler::stopWind()
{
windSFX.stop();
}
bool SoundHandler::playStorm()
{
if(!soundMuted)
stormSFX.play();
return true;
}
void SoundHandler::stopStorm()
{
stormSFX.stop();
}
bool SoundHandler::playRock()
{
if(!soundMuted)
rockSFX.play();
return true;
}
void SoundHandler::stopRock()
{
rockSFX.stop();
}
bool SoundHandler::playDeath()
{
if(!musicMuted)
deathSFX.play();
return true;
}
void SoundHandler::stopDeath()
{
deathSFX.stop();
}
bool SoundHandler::playBlood1()
{
if(!soundMuted)
blood1SFX.play();
return true;
}
void SoundHandler::stopBlood1()
{
blood1SFX.stop();
}
bool SoundHandler::playBirds()
{
if(!soundMuted)
birdSFX.play();
return true;
}
void SoundHandler::stopBirds()
{
birdSFX.stop();
}
bool SoundHandler::playKill()
{
if(!soundMuted)
killSFX.play();
return true;
}
void SoundHandler::stopKill()
{
killSFX.stop();
}
bool SoundHandler::playPop()
{
if(!soundMuted)
popSFX.play();
return true;
}
void SoundHandler::stopPop()
{
popSFX.stop();
}
bool SoundHandler::playSplat()
{
if(!soundMuted)
splatSFX.play();
return true;
}
void SoundHandler::stopSplat()
{
splatSFX.stop();
}
void SoundHandler::playCharge()
{
if(!soundMuted)
chargeSFX.play();
chargeSFX.setPitch(chargeSFX.getPitch() + .1);
}
void SoundHandler::resetCharge()
{
chargeSFX.setPitch(.1);
}
void SoundHandler::playFishing()
{
if(!musicMuted)
fishing.play();
}
void SoundHandler::stopFishing()
{
fishing.stop();
}
void SoundHandler::playSplash()
{
if(!soundMuted)
splashSFX.play();
}
void SoundHandler::playWater()
{
waterSFX.setPitch((rand() % 20) * .1 + .1);
if(!soundMuted)
waterSFX.play();
}
void SoundHandler::playCrickets()
{
if(!soundMuted)
cricketsSFX.play();
}
void SoundHandler::stopCrickets()
{
if(!soundMuted)
cricketsSFX.stop();
}
void SoundHandler::playMain()
{
if(!musicMuted)
main.play();
}
void SoundHandler::playNight()
{
if(!soundMuted)
night.play();
}
void SoundHandler::playFire()
{
if(!soundMuted)
fireSFX.play();
}
void SoundHandler::playMusicbox()
{
musicOn = false;
stopMusic();
musicboxSFX.stop();
if(!soundMuted && !musicMuted)
{
musicboxSFX.play();
stabSFX.play();
}
}
void SoundHandler::stopMusicbox()
{
musicboxSFX.stop();
}
void SoundHandler::playCombat()
{
if(!soundMuted)
combatSFX.play();
}
void SoundHandler::playType()
{
if(!soundMuted)
typeSFX.play();
}
void SoundHandler::playFeet()
{
if(!soundMuted)
feetSFX.play();
}
void SoundHandler::playPuff()
{
if(!soundMuted)
puffSFX.play();
}
void SoundHandler::playStab()
{
if(!soundMuted)
stabSFX.play();
}
For the sake of "minimal and complete examples", here is an example main function:
#include "SoundHandler.hpp"
int main()
{
SoundHandler soundHandler;
soundHandler.load();
soundHandler.handleMusic();
soundHandler.playCombat();
return 0;
}
Of course, this probably will not crash it since it crashes randomly when I play sounds. I haven't been able to solidly reproduce it yet repeatedly, so I apologize for lack of information.
My guess is that it may have to do with music being loaded at the same time as sounds? That's just a guess from my debugging, but I can't be sure.
All of the sounds are <1 second and the music is anywhere from 30 secs to 5 minutes.
Also, this occasionally gets output in my console and in other's:
Any ideas?