xenko icon indicating copy to clipboard operation
xenko copied to clipboard

Game crashes on startup with NullReferenceException in TouchInputsRenderer

Open agiro8747 opened this issue 7 years ago • 8 comments

I made an utterly simple scene: placed a sphere with a collider and a rigidbody, placed a cube mesh with a collider for the sphere to bounce off of, and placed a perspective camera with the slot set to main and run the game on Windows. I didn't write a single line of code. It crashed with the following:

[Game]: Error: Unexpected exception. System.NullReferenceException: object reference not set to an instance of the object. on the following place: FirstXenkoGame.TouchInputsRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) location: C:\Users\ragos\OneDrive\Documents\Xenko Projects\FirstXenkoGame\FirstXenkoGame\FirstXenkoGame.Game\TouchInputsRenderer.cs, line: 47 on the following place: SiliconStudio.Xenko.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Compositing\SceneRendererBase.cs, line: 48 on the following place: SiliconStudio.Xenko.Rendering.Compositing.GraphicsCompositor.DrawCore(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Compositing\GraphicsCompositor.cs, line: 168 on the following place: SiliconStudio.Xenko.Rendering.RendererBase.Draw(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\RendererBase.cs, line: 49 on the following place: SiliconStudio.Xenko.Engine.SceneSystem.Draw(GameTime gameTime) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Engine\SceneSystem.cs, line: 217 on the following place: SiliconStudio.Xenko.Games.GameSystemCollection.Draw(GameTime gameTime) on the following place: SiliconStudio.Xenko.Games.GameBase.Draw(GameTime gameTime) on the following place: SiliconStudio.Xenko.Games.GameBase.DrawFrame() on the following place: SiliconStudio.Xenko.Games.GameBase.TickInternal() System.NullReferenceException: object reference not set to an instance of an object. on the following place: FirstXenkoGame.TouchInputsRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) location: C:\Users\ragos\OneDrive\Documents\Xenko Projects\FirstXenkoGame\FirstXenkoGame\FirstXenkoGame.Game\TouchInputsRenderer.cs, sor: 47 on the following place: SiliconStudio.Xenko.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Compositing\SceneRendererBase.cs, line: 48 on the following place: SiliconStudio.Xenko.Rendering.Compositing.GraphicsCompositor.DrawCore(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Compositing\GraphicsCompositor.cs, sor: 168 on the following place: SiliconStudio.Xenko.Rendering.RendererBase.Draw(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\RendererBase.cs, line: 49 on the following place: SiliconStudio.Xenko.Engine.SceneSystem.Draw(GameTime gameTime) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Engine\SceneSystem.cs, line: 217 on the following place: SiliconStudio.Xenko.Games.GameSystemCollection.Draw(GameTime gameTime) on the following place: SiliconStudio.Xenko.Games.GameBase.Draw(GameTime gameTime) on the following place: SiliconStudio.Xenko.Games.GameBase.DrawFrame() on the following place: SiliconStudio.Xenko.Games.GameBase.TickInternal()

Unhandled exception: System.NullReferenceException: object reference not set to an instance of the object. on the following place: FirstXenkoGame.TouchInputsRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) location: C:\Users\ragos\OneDrive\Documents\Xenko Projects\FirstXenkoGame\FirstXenkoGame\FirstXenkoGame.Game\TouchInputsRenderer.cs, line: 47 on the following place: SiliconStudio.Xenko.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Compositing\SceneRendererBase.cs, line: 48 on the following place: SiliconStudio.Xenko.Rendering.Compositing.GraphicsCompositor.DrawCore(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Compositing\GraphicsCompositor.cs, line: 168 on the following place: SiliconStudio.Xenko.Rendering.RendererBase.Draw(RenderDrawContext context) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Rendering\RendererBase.cs, line: 49 on the following place: SiliconStudio.Xenko.Engine.SceneSystem.Draw(GameTime gameTime) location: C:\TeamCity\work\80a49494ba341a6a\sources\engine\SiliconStudio.Xenko.Engine\Engine\SceneSystem.cs, line: 217 on the following place: SiliconStudio.Xenko.Games.GameSystemCollection.Draw(GameTime gameTime) on the following place: SiliconStudio.Xenko.Games.GameBase.Draw(GameTime gameTime) on the following place: SiliconStudio.Xenko.Games.GameBase.DrawFrame() on the following place: SiliconStudio.Xenko.Games.GameBase.TickInternal() on the following place: SiliconStudio.Xenko.Games.GameBase.Tick() on the following place: SiliconStudio.Xenko.Games.GamePlatform.Tick() on the following place: SiliconStudio.Xenko.Games.GamePlatform.OnRunCallback() on the following place: SiliconStudio.Xenko.Games.GameWindowWinforms.<>c__DisplayClass19_0.<Run>b__0() on the following place: SiliconStudio.Xenko.Games.WindowsMessageLoop.Run(Control form, RenderCallback renderCallback, Boolean useApplicationDoEvents) on the following place: SiliconStudio.Xenko.Games.GameWindowWinforms.Run() on the following place: SiliconStudio.Xenko.Games.GamePlatform.Run(GameContext gameContext) on the following place: SiliconStudio.Xenko.Games.GameBase.Run(GameContext gameContext) on the following place: FirstXenkoGame.FirstXenkoGameApp.Main(String[] args) location: C:\Users\ragos\OneDrive\Documents\Xenko Projects\FirstXenkoGame\FirstXenkoGame\FirstXenkoGame.Windows\FirstXenkoGameApp.cs, line: 11

agiro8747 avatar Mar 17 '18 09:03 agiro8747

What is the code in "FirstXenkoGame.TouchInputsRenderer"?

dfkeenan avatar Mar 17 '18 11:03 dfkeenan

I have no clue, that's written by SiliconStudio. I didn't write a single line of code for this mini project-ling.

agiro8747 avatar Mar 17 '18 11:03 agiro8747

Well that file is in your project. what template did you use?

dfkeenan avatar Mar 17 '18 11:03 dfkeenan

New game for the platforms I select, I chose Windows and Android, but the game was started on Windows. btw yes indeed it was inside the folder. here it is:

   // Copyright (c) 2011-2017 Silicon Studio Corp. All rights reserved. (https://www.siliconstudio.co.jp)
        // See LICENSE.md for full license information.
    using System;
    using System.Collections.Generic;
    using SiliconStudio.Core.Mathematics;
    using SiliconStudio.Xenko.Engine;
    using SiliconStudio.Xenko.Rendering;
    using SiliconStudio.Xenko.Rendering.Compositing;
    using SiliconStudio.Xenko.Graphics;
    using SiliconStudio.Xenko.Input;

    namespace FirstXenkoGame
    {
        public class TouchInputsRenderer : SceneRendererBase
        {
            private SpriteBatch spriteBatch;
    
            private Vector2 virtualResolution = new Vector2(1920, 1080);
    
            public Texture Background;
    
            protected override void InitializeCore()
            {
                base.InitializeCore();
    
                // create the SpriteBatch used to render them
                spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = new     Vector3(virtualResolution, 1000) };
            }

            protected override void DrawCore(RenderContext context, RenderDrawContext drawContext)
            {
                // Clear
                drawContext.CommandList.Clear(drawContext.CommandList.RenderTarget, Color.Green);
                drawContext.CommandList.Clear(drawContext.CommandList.DepthStencilBuffer,     DepthStencilClearOptions.DepthBuffer);

                // Draw background
                spriteBatch.Begin(drawContext.GraphicsContext);
                var target = drawContext.CommandList.RenderTarget;
                var imageBufferMinRatio = Math.Min(Background.ViewWidth / (float)target.ViewWidth,     Background.ViewHeight / (float)target.ViewHeight);
                var sourceSize = new Vector2(target.ViewWidth * imageBufferMinRatio, target.ViewHeight *     imageBufferMinRatio);
                var source = new RectangleF((Background.ViewWidth - sourceSize.X) / 2,     (Background.ViewHeight - sourceSize.Y) / 2, sourceSize.X, sourceSize.Y);
                spriteBatch.Draw(Background, new RectangleF(0, 0, virtualResolution.X, virtualResolution.Y),     source, Color.White, 0, Vector2.Zero);
                spriteBatch.End();

                // Draw touch inputs
                var entity = context.SceneInstance.RootScene.Entities[0]; // Note: there's only one entity in our     scene
                entity.Get<TouchInputsScript>().Render(drawContext, spriteBatch);    
            }
        }
    }

agiro8747 avatar Mar 17 '18 11:03 agiro8747

You format code like so:

```csharp
public Texture Background;
```

dfkeenan avatar Mar 17 '18 11:03 dfkeenan

Thanks, I went with a stackoverflow approach here (with the whitespaces).

agiro8747 avatar Mar 17 '18 11:03 agiro8747

Ok so the problem is the last couple of lines in the DrawCore method

// Draw touch inputs
var entity = context.SceneInstance.RootScene.Entities[0]; // Note: there's only one entity in our     scene
entity.Get<TouchInputsScript>().Render(drawContext, spriteBatch);

It is expecting the first entity in the scene to have a TouchInputsScript component. So you can either edit your scene to be like that, comment out those lines (which makes this renderer pointless), or open your GraphicsCompositor asset and remove the TouchInputsRenderer from it.

dfkeenan avatar Mar 17 '18 12:03 dfkeenan

Thanks, so it wasn't a bug after all.

agiro8747 avatar Mar 17 '18 12:03 agiro8747