This project is read-only.

Latest Silversprite build

Dec 18, 2009 at 8:41 AM

Hello everyone,

This is my first time here. Last night I downloaded the latest version of Silversprite and converted my XNA game.

Everything went a little smooth, until I tried to exit the game: it crashed on a 'Draw' call.

I'm pretty new to XNA and silversprite in general, so don't leap on me if I overlooked this in the original XNA code.

In my code, I've created a Screen Manager that handles the transitions between different screens, etc, like the normal practice in XNA tutorials and other games. When I call for my Screen Manager to Exit, I stepped through the process in the Silversprite Game Class.  Apparently, the game doesn't exit immediately, but steps through the rest of the game loop to draw all the screens. Unfortunately, my Screen Manager previously removed all screens and unloaded the content. So when the Game Class calls draw, it crashes because nothing is there.

This does not happen in the XNA version of the game. So my question is, do I need to restructure my screen manager differently? Do I simply need to protect my code in my try/catch blocks?

Or is this a misunderstanding of Silversprite. Can I use the code differently to avoid this problem?

AND.....anyone have an extension or handy tool for using music and sounds more effectively than the bare 'Media Player'? :D :D :D

Thanks in advance everyone. Great Job Bill!!! :D

Dec 18, 2009 at 12:12 PM

You shouldn't have to do any of these things, this is clearly a bug that needs to be fixed. Were you using the latest out of the source tree when you hit this issue?

Dec 18, 2009 at 1:00 PM

 

Yes I am using the latest release of silversprite: silversprite-36278

This is the structure of my game:

Main Game class has the following member:

public static CScreenManager ScreenManager;

 

 

Inside the main game class, I do the following to declare my screen manager:

 

// Init the screen Manager
ScreenManager = new CScreenManager(this);
this.Components.Add(ScreenManager);

 

Screen Manager -> has a 'List<BaseMenus> ' to cycle through and update. My screen manager ALSO has a custom SpriteBatch, which I named "CRelativeSpriteBatch." 

Main Menu is derived from BaseMenu. I have an event where a message box pops up when the user hits Escape. I fire another event when the user hits 'yes' to exit. Inside that event I have the following code:

 

this.Shutdown();
this.ExitScreen();
PDGame.ScreenManager.Game.Exit();

 

However, this code does not automatically call the main game class's 'OnExiting' event. In fact, that event is NEVER called. Here is the call stack after I call exit from the Screen Manager:

SilverArcade.SilverSprite.Graphics.Texture2D.Width.get() Line 109 + 0x6 bytes	
SilverArcade.SilverSprite.Graphics.Texture2D.SourceRect.get() Line 75 + 0x8 bytes	

SilverArcade.SilverSprite.Graphics.SpriteBatch.Draw(SilverArcade.SilverSprite.Graphics.Texture2D texture = {SilverArcade.SilverSprite.Graphics.Texture2D}, SilverArcade.SilverSprite.Vector2 position = {X:0 Y:0}, SilverArcade.SilverSprite.Rectangle? sourceRectangle = null, SilverArcade.SilverSprite.Graphics.Color color = {SilverArcade.SilverSprite.Graphics.Color}, float rotation = 0.0, SilverArcade.SilverSprite.Vector2 origin = {X:0 Y:0}, float scale = 1.0, SilverArcade.SilverSprite.Graphics.SpriteEffects effects = None, float layerDepth = 0.0) Line 187 + 0x17 bytes	
 
ZenithGameSilverlight.CRelativeSpriteBatch.Draw(SilverArcade.SilverSprite.Graphics.Texture2D texture = {SilverArcade.SilverSprite.Graphics.Texture2D}, SilverArcade.SilverSprite.Vector2 position = {X:0 Y:0}, SilverArcade.SilverSprite.Graphics.Color color = {SilverArcade.SilverSprite.Graphics.Color}) Line 67	
 
ZenithGameSilverlight.CBaseMenuScreen.Draw(ZenithGameSilverlight.CRelativeSpriteBatch _spriteBatch = {ZenithGameSilverlight.CRelativeSpriteBatch}, SilverArcade.SilverSprite.GameTime _gameTime = {SilverArcade.SilverSprite.GameTime}) Line 176	
 
ZenithGameSilverlight.CMainMenu.Draw(ZenithGameSilverlight.CRelativeSpriteBatch _spriteBatch = {ZenithGameSilverlight.CRelativeSpriteBatch}, SilverArcade.SilverSprite.GameTime _gameTime = {SilverArcade.SilverSprite.GameTime}) Line 173	
 
ZenithGameSilverlight.CScreenManager.Draw(SilverArcade.SilverSprite.GameTime gameTime = {SilverArcade.SilverSprite.GameTime}) Line 170	
 
SilverArcade.SilverSprite.GameComponentCollection.Draw(SilverArcade.SilverSprite.GameTime gameTime = {SilverArcade.SilverSprite.GameTime}) Line 216 + 0x2d bytes

SilverArcade.SilverSprite.Game.Draw(SilverArcade.SilverSprite.GameTime gameTime = {SilverArcade.SilverSprite.GameTime}) Line 284	

ZenithGameSilverlight.PDGame.Draw(SilverArcade.SilverSprite.GameTime gameTime = {SilverArcade.SilverSprite.GameTime}) Line 228
	
 SilverArcade.SilverSprite.Game.Tick() Line 193
	
 SilverArcade.SilverSprite.Game.CompositionTarget_Rendering(object sender = {System.Windows.Threading.Dispatcher}, System.EventArgs e = {System.Windows.Media.RenderingEventArgs}) Line 206	

You can clearly see that the Silversprite Game Class continues on to the Draw calls, even after Exit was called. Is this my mistake, because of the way I declared my Screen Manager?

Thanks for your help!

Dec 18, 2009 at 10:04 PM

I have checked in some fixes, please try again and let me know. You should now get the Exiting event and it should stop processing after the Exit call.

Dec 19, 2009 at 5:51 PM

Hey Bill,

 

Thanks for adding those updates! It fixed the problems just fine and exits instantly. The 'OnExiting' event for the main game class isn't called, but that might be my own fault :)

But that did that trick. Thanks!

Dec 20, 2009 at 2:05 AM

Ok great, thanks. This is the way it typically goes, I need to rely on people trying their games out to tell me if something goes wrong. I don't have the capacity to test every little nuance of the XNA API and make sure we handle it properly. So if you find anything that behaves oddly let me know and I'll try to fix it. The goal is to make it behave like XNA as much as possible to make porting XNA apps easier.

Jul 3, 2010 at 3:50 PM

I have a question... every new version that appears in the "Source Code" section of the web... do we simply deploy them to have them working or is there something else to it?