I started coding a simple game in Windows Form C#, but after I added the background sound (a simple .wav file) when I run the game, after a few second of playing the game crashes. (The sound can be heard).
Here is the function:
private void playAmbientSound()
{
System.Media.SoundPlayer playAmbient = new System.Media.SoundPlayer(Properties.Resources.ambient);
playAmbient.PlayLooping();
}
Then I call this function from the function resetGame() a function used in the Form constructor.
public Form1()
{
InitializeComponent();
resetGame();
}
The code that appears in the console after the crash is:
.. has exited with code -1073741819 (0xc0000005) 'Access Violation'".
As requested here is the resetGame() function:
private void resetGame()
{
btnStart.Enabled = false;
explosion.Visible = false;
award.Visible = false;
goLeft = false;
goRight = false;
score = 0;
award.Image = Properties.Resources.bronze;
roadSpeed = 12;
trafficSpeed = 15;
AI1.Top = carPosition.Next(200, 500) * -1;
AI1.Left = carPosition.Next(5, 200);
AI2.Top = carPosition.Next(200, 500) * -1;
AI2.Left = carPosition.Next(245, 422);
playAmbientSound();
gameTimer.Start();
}
User contributions licensed under CC BY-SA 3.0