VG:Game Crashes (VG2)

From MyProjectFun
Jump to: navigation, search


My game crashes when I run it, what should I do?

This is where our friend the call stack comes in handy. If we don't have the call stack open, we can find it under Debug > Windows > Call Stack only when the game is running. Basically, we want to backtrack on the call stack until we hit code we actually wrote, which will usually point out that we have a spelling mistake in one of the supplied filenames.

Always watch your spelling!

Okay, my call stack has brought me to where I made the background. What now?

new Background( "Background" , "Background.png" );

Well, there's a few things that could be wrong here. First of all, make sure that the first parameter to the function is the name we want to call our background. Secondly, make sure the second parameter is the filename of our background. After that, try these:

  • Make sure you have the .png, as we do need the file type for the filename!
  • Make sure that the your filename matches the art you've made for your background!
  • Make sure your art is in the correct folder. It should be in the Maps folder under Art Assets!
  • Make sure your Art Assets folder is in the same folder as your project!
  • Make sure your Art Assets, Actors, Maps, and Sounds folders are named correctly (spelled and capitalized as I have them here)!

Hey! I start the game and it pops up with a window saying something along the lines of "Actor was not found while creating sprite PlayerActor"

In this case, your sprite is trying to use an actor that doesn't exist. This problem can stem from a spelling mistake or forgetting to add your actor. Double check your spelling where you're making your sprite.

Sprite Player = new Sprite( "Player" , "PlayerActor" ); 

Make sure that second part about the PlayerActor matches the spelling for when you create the actor in MyGame.cs under the CreateResources function.

Actor PlayerActor = new Actor("PlayerActor");

If the names don't match, the game will crash because it can't find the actor for your sprite.

I have a box pop up that says something about levels, kinda like this "Level 'Arena' does not exist."

Well, this is very similar to the actor problem, but it has to do with our levels. We'll want to check the parts in our code that have to do with making the level (where we give it its name) and where we try to load the level (which requires the level's name).

For example:

Level Arena = new Level(" Arena");



Notice that we accidentally added a space in our level name when we made it. So, to fix this, we make the names match (preferably by changing " Arena" to "Arena" - our intended level name).

When I run my game, it stops at some random line of code, so I used the call stack to figure out the offending line of code, which looks like "Bullet.AddAnimation(AnimationLoader.load("Bullet"));"

Everything seems to be in order here, but maybe we're not using this code quite right. The name we pass into the AnimationLoader.load function needs to be the name of our animation file that we made using the animation editor.

If your name passed into the function does not match that of the .anim file (excluding the .anim, of course), then make them match.

If you don't have a .anim file with that name, then you need to make one before you try to load it.

How about this one - when I run my game, it crashes and the call stack takes me to section of code about spawning enemies, which looks kinda like this "Sprite Snake = new Sprite(SnakeMaster);"

This is one of the most common problems. This line should be very near another line that looks like

Sprite SnakeMaster = This.Game.FindSprite("SnakeMaster");

If you were to mouse over SnakeMaster while debugging after the crash, you might see a little pop-up box saying SnakeMaster | null. This means that we couldn't find any sprite with the name "SnakeMaster" and the game returned null to our sprite SnakeMaster.

So, how to fix this. First, we want to make sure that when we make the sprite we intended to call "SnakeMaster" is actually named correctly. This is a great time to check our spelling and capitalization carefully.

If we have no such sprite at all, then we should either add a sprite with that name or, if we never intended to copy the SnakeMaster in this level, remove the behavior that is running that code from the level.

Personal tools
Game Design
Multimedia Production
VG Programming