Hi,Whenever I start my game, it seems to run quite fine. Upon opening the editor, it crashes.I've crunched through a number of solutions and bugs with answers from this forum, mainly in unloading and reloading content, managers and render targets.But this one line has me stumped. g_GameManager.GET.sceneInterface.RenderManager.Render();When I peek into it with the debugger, the SceneState object within the RenderManager seems fine.When I open the editor, it crashes here and the scenestate within the rendermanager is null."An unhandled exception of type 'System.NullReferenceException' occurred in SynapseGaming-SunBurn-Community.dll
Additional information: Object reference not set to an instance of an object."What would be causing this and what steps can I take to stop SceneState from nulling out?
Hi 2.0,
Can you post the stack trace? It will help us see what's happening.
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
"Stack trace" is a term I am unfamiliar with. Is this it? If not how do I get one?//---------------------- SynapseGaming-SunBurn-Community.dll!SynapseGaming.LightingSystem.Rendering.Deferred.DeferredRenderManager.Render() + 0xad bytes > BasicSetupDemo.exe!GameStateManagement.GameplayScreen.Draw(Microsoft.Xna.Framework.GameTime gameTime = {Microsoft.Xna.Framework.GameTime}) Line 335 + 0x21 bytes C# BasicSetupDemo.exe!GameStateManagement.g_ScreenManager.Draw(Microsoft.Xna.Framework.GameTime gameTime = {Microsoft.Xna.Framework.GameTime}) Line 193 + 0xb bytes C# Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime gameTime = {Microsoft.Xna.Framework.GameTime}) + 0xba bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.DrawFrame() + 0x164 bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Tick() + 0x828 bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.HostIdle(object sender = {Microsoft.Xna.Framework.WindowsGameHost}, System.EventArgs e = {System.EventArgs}) + 0x23 bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.GameHost.OnIdle() + 0x3d bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(object sender = {System.Threading.Thread}, System.EventArgs e = {System.EventArgs}) + 0x60 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(int grfidlef) + 0x37 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x33f bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x177 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.WindowsGameHost.Run() + 0x90 bytes Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Run() + 0x178 bytes BasicSetupDemo.exe!Ragdoll_Dismount.Program.Main(string[] args = {string[0]}) Line 12 + 0xb bytes C#//---------------------------- Jarryd
Cool, thanks. Make sure BeginFrameRendering() is being called before Render() and EndFrameRendering() after (while the editor is open).
Ok, that was not the solution but it did let me find the source of the problem, and fix it. Thankyou!But now I have a question regarding sunburn and render targets.Our game works by rendering everything to a render target, then spitting that to a texture. From there we then use shaders to mess with the final image. After that we then just render the final image as a texture, using a sprite batch.Here is a cut down version of our draw call: public void TestingDraw(GameTime in_GameTime) {
MainGame.GET.MainGameTarget.BeginFrameRendering(g_GameManager.GET.sceneState); g_GameManager.GET.sceneState.BeginFrameRendering(g_Camera3D.GET.ViewMatrix, g_Camera3D.GET.ProjectionMatrix, in_GameTime, g_GameManager.GET.environment);
g_GameManager.GET.sceneInterface.BeginFrameRendering(MainGame.GET.MainGameTarget.SceneState, g_GameManager.GET.deferredBufferManager); g_GameManager.GET.editor.BeginFrameRendering(g_GameManager.GET.sceneState);
//-------------- g_GameManager.GET.sceneInterface.RenderManager.Render(); //--------------
g_GameManager.GET.editor.EndFrameRendering(); g_GameManager.GET.sceneInterface.EndFrameRendering();
g_GameManager.GET.sceneState.EndFrameRendering(); MainGame.GET.MainGameTarget.EndFrameRendering(); MainGame.GET.MainBBTexture = MainGame.GET.MainGameTarget.GetTexture();
if (MainGame.GET.MainBBTexture != null) { g_Camera2D.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState); g_Camera2D.SpriteBatch.Draw(MainGame.GET.MainBBTexture, new Rectangle(0, 0, 1280, 720), Color.White); g_Camera2D.SpriteBatch.End(); }
base.Draw(in_GameTime); }When I take away the MainGameTarget (its a RenderTargetHelper) calls to begin and end, it all runs great when the editor is running. Put them back, and it breaks because the SceneState is somehow null inside the render manager.So how is it that the scenestates are effecting each other? And how is it meant to be done? For now I can just check if the editor is attatched.-- Jarryd.
There are a few extra calls to Begin / End in there. You might want to take a look at the Reflection / Refraction example, it shows how to use the scene interface and render target helpers together.
Assuming the editor is added to the scene interface the pseudo code for using them together would look like this:
// note: the target takes the main scene state, then // the scene interface uses the target's state. This allows // automatic reflections when the target type is reflection. target.BeginFrameRendering(sceneState); sceneInterface.BeginFrameRendering(target.SceneState); // Render the scene. sceneInterface.RenderManager.Render(); sceneInterface.EndFrameRendering(); target.EndFrameRendering();
Also see if the MainGame.GET.MainGameTarget.SceneState property is also null. This will help determine if the object is null or the manager's internal reference is being lost.
Cool, thankyou for that.