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

Crash when editing imgui demo. #111

Open
Shadowblitz16 opened this issue Jul 11, 2021 · 2 comments
Open

Crash when editing imgui demo. #111

Shadowblitz16 opened this issue Jul 11, 2021 · 2 comments

Comments

@Shadowblitz16
Copy link

I am getting a crash when I try to run game which is based on the imgui demo.

/home/shadowblitz16/RiderProjects/PlatformerEngine/PlatformerEngine/bin/Debug/net5.0/PlatformerEngine
Unhandled exception. System.TypeInitializationException: The type initializer for 'Love.Love2dDll' threw an exception.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Love.Boot.GetLibraryFunc(String name)
   at Love.Love2dDll.LoadFunction[T](String name)
   at Love.Love2dDll..cctor()
   --- End of inner exception stack trace ---
   at Love.Image.NewImageData(Int32 w, Int32 h, ImageDataPixelFormat format, Byte[] data)
   at Love.Imgui.Renderer.RebuildFontAtlas()
   at Love.Imgui.Renderer..ctor(String fontPath, Single fontSize, Func`2 imageLoader)
   at PlatformerEngine.Game..ctor() in /home/shadowblitz16/RiderProjects/PlatformerEngine/PlatformerEngine/Game.cs:line 15
   at PlatformerEngine.Program..ctor()
   at PlatformerEngine.Program.Main(String[] args) in /home/shadowblitz16/RiderProjects/PlatformerEngine/PlatformerEngine/Program.cs:line 7

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Love;
using System.IO;
using ImGuiNET;
using Love.Imgui;

namespace PlatformerEngine
{
    public abstract class Game : IDisposable
    {
        private Renderer _imGuiRenderer = new Renderer("G:/font/msyh.ttf", 18);
        private Runner   _imGuiRunner;

        public GameConfig Config { get; private set; }
        
        private class Runner : Scene
        {
            
        }

        protected virtual void OnGUI ()
        {
            
        }
        protected virtual void OnLoad()
        {
            
        }
        protected virtual void OnTick()
        {
            
        }
        protected virtual void OnDraw()
        {

        }
        protected virtual void OnQuit()
        {
            
        }

        public void Run(GameConfig config)
        {
            var asy = System.Reflection.Assembly.GetAssembly(typeof(Boot));
            Console.WriteLine(asy);
            
            Config = config;

            _imGuiRunner = new Runner();
            _imGuiRunner.OnLoad += () =>
            {
                Console.WriteLine(ImGui.GetVersion());
                OnLoad();
            };

            _imGuiRunner.OnUpdate += dt =>
            {
                _imGuiRenderer.Update(dt, OnGUI);
                OnTick();
            };

            _imGuiRunner.OnDraw += () =>
            {
                _imGuiRenderer.Draw();
                OnDraw();
            };
            
            _imGuiRunner.OnQuit += () =>
            {
                OnQuit();
                return false;
            };

            _imGuiRunner.OnTextInput += text =>
            {
                _imGuiRenderer.TextInput(text);
            };
            
            Boot.Init(new BootConfig()
            {
                WindowVsync      = Config.VSync,
                WindowTitle      = Config.Title,  
                WindowWidth      = (int)Config.Width,
                WindowHeight     = (int)Config.Height,
                WindowResizable  = Config.Resizable,
                WindowFullscreen = Config.Fullscreen
            });
            Boot.Run(_imGuiRunner);
        }

        public void Dispose()
        {
            Love.Event.Quit(0);
        }
    }

    public sealed class GameConfig
    {
        public bool   VSync      { get; set; }
        public string Title      { get; set; }
        public uint   Width      { get; set; }
        public uint   Height     { get; set; }
        public bool   Resizable  { get; set; }
        public bool   Fullscreen { get; set; }
    }
}
namespace PlatformerEngine
{
    public class Program : Game
    {
        public static void Main(string[] args)
        {
            using (var game = new Program())
            {
                game.Run(new GameConfig()
                {
                    Width  = 1080, 
                    Height = 640
                });
            }
        }
    }
}
@endlesstravel
Copy link
Owner

🤔 I am not sure what happened, but here is information i can provide for you:

  • LoveSharp.Imgui need LoveSharp nuget library but not Love2dCS
  • the best way to run the deamo is clone all of this : https://github.com/endlesstravel/LoveSharp.Imgui

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Jul 16, 2021

I think it installs LoveSharp as a dependency.
also I based it off the demo there.

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

2 participants