mocha-engine / mocha

Mocha: A work-in-progress 3D game engine
GNU Lesser General Public License v3.0
53 stars 7 forks source link

Hotloading throws when upgrading instances of abstract classes #28

Closed MuffinTastic closed 1 year ago

MuffinTastic commented 1 year ago

Reproduction

  1. Put this in Game.cs
// ...

public abstract class Abstract { }

public class Implementation : Abstract
{
    public int Field;
    public string Property { get; set; }
}

public class Game : BaseGame
{
    // ...

    public Abstract _instance;

    public override void Startup()
    {
        // ...

        _instance = new Implementation
        {
            Field = 123,
            Property = "!olleH dlroW"
        };

        // ...
    }

    // ...
}
  1. Start Mocha, wait for the game to start
  2. Save Game.cs to trigger a hotload
  3. Witness image

Notes

Abstract classes and their implementations can obviously be from different assemblies, not sure what a clean way to handle that would be. Maybe something like this would work:

  1. If the old implementation type is from the assembly we're swapping out, attempt to get a class of the same name from the new assembly and instantiate that
  2. Else, just make a new instance of the old implementation type (It's probably from some .NET or Mocha assembly or something)

Just spitballing though

xezno commented 1 year ago

Think I fixed this in https://github.com/xezno/mocha/commit/7207eee41826ebe65e0ad96c3399693dc7a5a5b1, please re-open if that's not the case