Skip to content
This repository was archived by the owner on Aug 22, 2018. It is now read-only.

Game crashes on startup with NullReferenceException in TouchInputsRenderer #657

Open
agiro8747 opened this issue Mar 17, 2018 · 8 comments

Comments

@agiro8747
Copy link

agiro8747 commented Mar 17, 2018

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.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

@dfkeenan
Copy link

What is the code in "FirstXenkoGame.TouchInputsRenderer"?

@agiro8747
Copy link
Author

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

@dfkeenan
Copy link

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

@agiro8747
Copy link
Author

agiro8747 commented Mar 17, 2018

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);    
            }
        }
    }

@dfkeenan
Copy link

You format code like so:

```csharp
public Texture Background;
```

@agiro8747
Copy link
Author

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

@dfkeenan
Copy link

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.

@agiro8747
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants