Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiler Script throws null exception on startup #41

Closed
tebjan opened this issue Aug 4, 2018 · 6 comments
Closed

Profiler Script throws null exception on startup #41

tebjan opened this issue Aug 4, 2018 · 6 comments

Comments

@tebjan
Copy link
Member

tebjan commented Aug 4, 2018

If the main camera of the game has a profiler script attached and it is enabled, a null exception is thrown on startup:

[Game]: Error: Unexpected exception. System.NullReferenceException:
bei Xenko.Profiling.GameProfilingSystem.Draw(GameTime gameTime)
bei Xenko.Games.GameSystemCollection.Draw(GameTime gameTime)
bei Xenko.Games.GameBase.Draw(GameTime gameTime)
bei Xenko.Games.GameBase.DrawFrame()
bei Xenko.Games.GameBase.TickInternal()

if the script is disabled, the exception does not occur.

@aurodev
Copy link

aurodev commented Aug 6, 2018

We can confirm this.

Null ref also occurs when adding via script
Occurs at: game.ProfilingSystem.EnableProfiling();

TopDownRPG -> PlayerController.cs

using Xenko.Core.Diagnostics;
using Xenko.Games;
using Xenko.Profiling;
.
.
.
    public override void Start()
        {
            base.Start();
            .
            .
            .

            //Attempt to display FPS
            var game = (Game)Game;
            
            game.ProfilingSystem.EnableProfiling();

            Profiler.Enable(GameProfilingKeys.GameDrawFPS);
        }


[Game]: Error: Unexpected exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Xenko.Profiling.GameProfilingSystem.Draw(GameTime gameTime)
at Xenko.Games.GameSystemCollection.Draw(GameTime gameTime)
at Xenko.Games.GameBase.Draw(GameTime gameTime)
at Xenko.Games.GameBase.DrawFrame()
at Xenko.Games.GameBase.TickInternal()
System.NullReferenceException: Object reference not set to an instance of an object.
at Xenko.Profiling.GameProfilingSystem.Draw(GameTime gameTime)
at Xenko.Games.GameSystemCollection.Draw(GameTime gameTime)
at Xenko.Games.GameBase.Draw(GameTime gameTime)
at Xenko.Games.GameBase.DrawFrame()
at Xenko.Games.GameBase.TickInternal()

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Xenko.Profiling.GameProfilingSystem.Draw(GameTime gameTime)
at Xenko.Games.GameSystemCollection.Draw(GameTime gameTime)
at Xenko.Games.GameBase.Draw(GameTime gameTime)
at Xenko.Games.GameBase.DrawFrame()
at Xenko.Games.GameBase.TickInternal()
at Xenko.Games.GameBase.Tick()
at Xenko.Games.GamePlatform.Tick()
at Xenko.Games.GamePlatform.OnRunCallback()
at Xenko.Games.WindowsMessageLoop.Run(Control form, RenderCallback renderCallback, Boolean useApplicationDoEvents)
at Xenko.Games.GameWindowWinforms.Run()
at Xenko.Games.GameBase.Run(GameContext gameContext)
at TopDownRPG2.TopDownRPG2App.Main(String[] args) in C:\Users\Greg\Documents\Xenko\TopDownRPG2\TopDownRPG2\TopDownRPG2.Windows\TopDownRPG2App.cs:line 11
Press any key to continue . . .

@tebjan
Copy link
Member Author

tebjan commented Aug 6, 2018

was trying to fix it but had to do other stuff. if someone works on it, please comment here so we are not doing it twice.

@EternalTamago
Copy link
Contributor

GameProfiler's Content is null.
I think that ContentManager is not registered with Service before GameProfiler is created.
DebugText has same problem.

This script which is placed in Default Scene seems to work.

    public class RecreateGameProfilerAndDebugTextScript : StartupScript
    {
        public override void Start()
        {
            // GameProfiler
            GameProfiler.DisableProfiling();
            Game.GameSystems.Remove(GameProfiler);
            Services.RemoveService<GameProfilingSystem>();

            var gameProfiler = new GameProfilingSystem(Services);
            Services.AddService(gameProfiler);
            Game.GameSystems.Add(gameProfiler);

            // DebugText
            DebugText.Enabled = false;
            DebugText.Visible = false;
            Game.GameSystems.Remove(DebugText);
            Services.RemoveService<DebugTextSystem>();

            var debugText = new DebugTextSystem(Services);
            Services.AddService(debugText);
            Game.GameSystems.Add(debugText);

            // Reload current scene

            var result = Content.TryGetAssetUrl(SceneSystem.SceneInstance.RootScene, out var url);
            if (!result)
            {
            }

            Content.Unload(SceneSystem.SceneInstance.RootScene);

            var scene = Content.Load<Scene>(url);
            var script = scene.Entities.SelectMany((e) => e.Components).OfType<RecreateGameProfilerAndDebugTextScript>().First();
            script.Entity.Remove(script);

            SceneSystem.SceneInstance.RootScene = scene;
        }
    }

@tebjan
Copy link
Member Author

tebjan commented Aug 7, 2018

@EternalTamago thanks a lot, that workaround works!

@xen2
Copy link
Member

xen2 commented Nov 8, 2018

Supposed to be fixed by b887069
Please reopen if not working

@tebjan
Copy link
Member Author

tebjan commented Nov 8, 2018

yes, i can confirm that this is working now. thanks for the fix.

@tebjan tebjan closed this as completed Nov 8, 2018
Doprez pushed a commit to Doprez/stride that referenced this issue Apr 6, 2024
Easy performance gain but still crash sometimes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants