• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineIncorporating DeferredLightingSample into GameStatesSampleIncorporating DeferredLightingSample into GameStatesSample
Previous
 
Next
New Post
7/20/2012 4:28 PM
 
patt4179
No Ranking

Joined: 6/22/2012
Posts: 55
Incorporating DeferredLightingSample into GameStatesSample 

Hey,

I've been messing around with integrating several different pieces from the sample projects together, but I've run into an issue when trying to get a Graphics sample working correctly when switching from it back to a menu game state. I've actually got the sample loading up and running perfectly when you hit the start button on the menu, but it's when I return to the menu from the game where the issue occurs.

When I start the game, I add the level component to the game and then set the visibility of the UI component to false so it won't cover up the game, but will still receive update calls. Once I hit escape and return back to the main menu, I set the visibility and enabled properties for my Graphics level to false and then re-enable the visibility of the UI component.

This all works great for about half a second (the menu shows up), but then the game crashes. The graphics are still trying to draw things in the component even they they are "disposed" according to the exception. What's the best way to handle stopping a component using digital rune's graphics? Is there a property that will tell the screen to stop trying to draw until I want it to start again? I tried removing the component, disposing it, and just couldn't find a way that doesn't throw this exception. Any ideas at all would be greatly appreciated


Here's the code I'm using to go between the game states:

/// <summary>
/// Called when "Game" state is entered.
/// </summary>
private void OnEnterGameScreen(object sender, StateEventArgs eventArgs)
{
    if (level == null)
    {
        level = new Level01(Game);
        Game.Components.Add(level);
    }
    else
    {
        _inputService.EnableMouseCentering = true;
        level.Enabled = true;
        level.Visible = true;
    }
 
    this.Visible = false;
    Game.IsMouseVisible = false;
}
 
 
/// <summary>
/// Called every frame when "Game" state is active.
/// </summary>
private void OnUpdateGameScreen(object sender, StateEventArgs eventArgs)
{
    // Exit the "Game" state if Back button or Escape key is pressed.
    if (_inputService.IsPressed(Buttons.Back, false, LogicalPlayerIndex.One)
        || _inputService.IsPressed(Keys.Escape, false))
    {
        _stateMachine.States.ActiveState.Transitions["GameToMenu"].Fire();
    }
}
 
 
/// <summary>
/// Called when "Game" state is exited.
/// </summary>
private void OnExitGameScreen(object sender, StateEventArgs eventArgs)
{
    this.Visible = true;
    level.Visible = false;
    level.Enabled = false;           
    _inputService.EnableMouseCentering = false;
    Game.IsMouseVisible = true;
}

 
New Post
7/21/2012 1:38 AM
 
patt4179
No Ranking

Joined: 6/22/2012
Posts: 55
Re: Incorporating DeferredLightingSample into GameStatesSample 

I ended up getting it to go back to the menu now, but when I try to reverse the process and start the game up again, it crashes when it gets to _graphicsManager.Render(false); in the main Game loop. It's still throwing that exception about trying to use disposed objects. This is how I ended up getting it to at least go back to the menu:


/// <summary>
/// Called when "Game" state is entered.
/// </summary>
private void OnEnterGameScreen(object sender, StateEventArgs eventArgs)
{
    if (level == null)
    {
        level = new Level01(Game);
        Game.Components.Add(level);
    }
    else
    {
        _inputService.EnableMouseCentering = true;
        level.player.CenterMouse = true;
        level.ResumeMainScreen();
        level.Enabled = true;
        level.Visible = true;               
    }
 
    this.Visible = false;
    Game.IsMouseVisible = false;
}
 
 
/// <summary>
/// Called every frame when "Game" state is active.
/// </summary>
private void OnUpdateGameScreen(object sender, StateEventArgs eventArgs)
{
    // Exit the "Game" state if Back button or Escape key is pressed.
    if (_inputService.IsPressed(Buttons.Back, false, LogicalPlayerIndex.One)
        || _inputService.IsPressed(Keys.Escape, false))
    {
        _stateMachine.States.ActiveState.Transitions["GameToMenu"].Fire();
    }
}
 
 
/// <summary>
/// Called when "Game" state is exited.
/// </summary>
private void OnExitGameScreen(object sender, StateEventArgs eventArgs)
{
    this.Visible = true;
    level.PauseMainScreen();
    level.Visible = false;
    level.Enabled = false;
    level.player.CenterMouse = false;
    _inputService.EnableMouseCentering = false;
    Game.IsMouseVisible = true;
}

The two methods for Pause and ResumeMainScreen just take the Default screen and set it's visibility to false so it doesn't keep trying to render when it shouldn't be. I must still not be approaching this in the right way though since when I try to resume the game, it throws the same exception as before.

 
New Post
7/21/2012 11:30 AM
 
MartinG
7th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 446
Re: Incorporating DeferredLightingSample into GameStatesSample 

Currently I don't know what could cause the exception.
Can you please post the full exception message + stack trace.
Are you explicitly calling a Dispose() method somewhere in your code?
What does the Level01.Visible property do?

If you use the code "as is" from the DeferredLightingSample, you can start/stop the Level01 using the following code.

// Start level
Level01 level01 = new Level01(Game);
Game.Components.Add(level01);
 
// Stop level
Game.Components.Remove(level01);
level01.Dispose();
level01 = null;

If you just want to temporarily suspend drawing, you can set the IsVisible flag of the graphics screens in Level01 (DeferredLightingScreen, HelpGraphicsScreen) to false. Or you can temporarily remove the graphics screens from the graphics service. 

For example, you could override GameComponent.OnEnabledChanged() method and put the code to enable/disable drawing there. Then setting the level01.Enabled property should have the desired effect.

Let me know if this information was helpful.

 
 Page 1 of 1
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineIncorporating DeferredLightingSample into GameStatesSampleIncorporating DeferredLightingSample into GameStatesSample


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement