Hi,
I get this error message (in fact, 3 same messages) in the Windows console after closing the window:
An internal OpenAL call failed in SoundBuffer.cpp (75) : AL_INVALID_OPERATION, the specified operation is not allowed in the current state
and the program also crashes ("the program has stopped working" window) with the following details:
Problem signature:
Problem Event Name: APPCRASH
Application Name: Mastermind.exe
Application Version: 0.1.3.2
Application Timestamp: 530db220
Fault Module Name: MSVCP110D.dll
Fault Module Version: 11.0.51106.1
Fault Module Timestamp: 50988588
Exception Code: c0000005
Exception Offset: 0000f069
OS Version: 6.1.7601.2.1.0.256.48
Everything in my program is working. Audio and everything else is fine but after closing the program it crashes.
I don't know what code to post, so I'll just post the sound system stuff:
soundsystem.h:
#ifndef __SOUNDSYSTEM_H__
#define __SOUNDSYSTEM_H__
#include <string>
#include <SFML/Audio.hpp>
class SoundSystem {
public:
SoundSystem();
virtual ~SoundSystem();
void setAudioEnabled(bool status) { audioEnabled_ = status; };
void setMenuSoundsEnabled(bool status) { menuSoundsEnabled_ = status; };
void setGameSoundsEnabled(bool status) { gameSoundsEnabled_ = status; };
void forceDisabledAudio() { disabledAudioForced_ = true; };
bool audioEnabled() const { return audioEnabled_; };
bool menuSoundsEnabled() const { return menuSoundsEnabled_; };
bool gameSoundsEnabled() const { return gameSoundsEnabled_; };
unsigned int getSoundVolume() const { return soundsVolume_; };
bool disabledAudioForced() const { return disabledAudioForced_; };
void playSound(const std::string &soundName);
void setSoundsVolume(unsigned int volume);
void stopAll();
private:
int maximumSounds_;
sf::Sound sounds_[30];
bool audioEnabled_;
bool menuSoundsEnabled_;
bool gameSoundsEnabled_;
unsigned int soundsVolume_;
int lastSoundPlayed_;
bool disabledAudioForced_;
};
#endif
soundsystem.cpp:
#include "soundsystem.h"
#include "config.h"
#include "resources.h"
SoundSystem::SoundSystem() :
maximumSounds_(30),
audioEnabled_(true),
menuSoundsEnabled_(true),
gameSoundsEnabled_(true),
soundsVolume_(50),
lastSoundPlayed_(0),
disabledAudioForced_(false)
{
}
SoundSystem::~SoundSystem() {
}
void SoundSystem::playSound(const std::string &soundName) {
if (audioEnabled_) {
if (lastSoundPlayed_ == maximumSounds_) {
lastSoundPlayed_ = 0;
}
sf::Sound &sound = sounds_[lastSoundPlayed_];
if (sound.getStatus() == sf::Sound::Playing) {
sound.stop();
}
sound.setBuffer(resourceHolder.getSoundBuffer(soundName));
sound.setPitch(1);
sound.play();
++lastSoundPlayed_;
}
}
void SoundSystem::setSoundsVolume(unsigned int volume) {
if (volume > 100) {
volume = 100;
}
soundsVolume_ = volume;
for (int i = 0; i < maximumSounds_; ++i) {
sounds_[i].setVolume((float)volume);
}
}
void SoundSystem::stopAll() {
for (int i = 0; i < maximumSounds_; ++i) {
if (sounds_[i].getStatus() == sf::Sound::Playing) {
sounds_[i].stop();
}
}
}
Before closing the window I call SoundSystem's stopAll() if that's relevant.
Could anyone please help me?
Okay first off let me just thank you for helping me!
Cool stack trace, but with a complete and minimal code example that reproduces the error, it's impossible to tell what's going on. ;D
Well yeah, but unfortunately the test program I just made doesn't crash and posting my original project isn't really a good idea because I have a whole lot of code lines spread across 40+ files.
I'll see if I can reproduce the errors and crash with a minimal example but I'm not that optimistic. I'll try my best!
Do you use static/global variables?
I'm not using global or static variabales at all except for one static variable
static Resources resourceHolder;
declared in config.h. It hasn't produced any errors earlier though. Hm...
I'm not using global or static variabales at all except for one static variable
static Resources resourceHolder;
declared in config.h. It hasn't produced any errors earlier though. Hm...
One is enough when it is the class that manages the resources. There are enough topics floating around why static and global variables should never be used with SFML resources and nearly never in any other situation.
Think of a better design that doesn't require you to make things globally available. ;)