I'm writing a game where player picks coins. Picking a coin there is supposed to be a sound, I use PlaySound to play *.wav file. It works. But sometimes (7/10 attempts) app just crushes. I have no idea why sometimes is works and sometimes it doesn't.
The interesting thing is when I run the app in debug mode it works perfectly
What can cause the problem and how can it be fixed?
And also can you recommend another way to play wav? (As simple as that (Using one-two functions))
I've tried to use PlaySoundA, sndPlaySound all of the variations - the same result
tried to read wav directly from file and save it in memory - the same result
//This sample checks if there a coin on the right
void Player::step_right() {
if (check_right()) {
sndPlaySound(TEXT("D:\\projects\\s.wav"), SND_FILENAME | SND_ASYNC);
//PlaySoundA(TEXT("D:\\projects\\s.wav"), nullptr, SND_FILENAME | SND_ASYNC);
//sndPlaySound(buffer, SND_MEMORY || SND_ASYNC);
netWorth++;
steps+=10;
}
cur->X++;
}
upd: I use MinGW
Console output after crush: Process finished with exit code -1073741819 (0xC0000005)
Here is the Player class specification:
class Player {
private:
Point* cur; // Current coords
Point post; // Last coords
int steps; // Remaining steps
int netWorth; // Picked coins
void (Player::*m[4])(); // Array of movement functions pointers
// Movement
void step_right();
void step_left();
void step_up();
void step_down();
// Coins checking
bool check_right();
bool check_left();
bool check_up();
bool check_down();
public:
Player();
Point* Getcur() { return cur; }
void Move(void (Player::*t)());
bool isOutofSteps();
auto ReturnSomeArray() { return m; }
int GetNet(); //Networth
void display_player_info();
};
I also have Action_Listener class which has
map<int, void (Player::*)()> m;
Depending on a keycode I send a function pointer to void Player::Move(void (Player::*t)())
here:
if (m.find(event) != m.end() && !player->isOutofSteps()) {
void (Player::*t)() = m[event];
player->Move(t);
unsigned int (Drawer::*y)() = drawhandlers[event];
drawer->Draw_Hero(y);
player->display_player_info();
} else if(player->isOutofSteps()){
terminal_print(2, 2, "You're out of steps");
return;
}
Move function:
void Player ::Move(void (Player::*t)()) {
post = *cur;
(this->*t)();
steps--;
}
User contributions licensed under CC BY-SA 3.0