Questions regarding LIVE_UPDATE

I have a couple questions regarding LIVE_UPDATE.
My goal is writing a simple level editor that updates texture and model files on the fly.

Firstly, I initialize hxd.Res like this:

static function main()
{
    hxd.Res.initLocal();
    hxd.res.Resource.LIVE_UPDATE = true;
    
    new Main();
}

…and then load a simple model (binary .fbx format) with attached texture (.png format):

var cache:h3d.prim.ModelCache;
var obj:h3d.scene.Object;

overrride function init()
{
    cache = new h3d.prim.ModelCache();
    obj = cache.loadModel(hxd.Res.gfx.terrains.plane);

    s3d.addChild(obj);
}

…and when I compile, run and then edit my texture file the live reload does work fine.
But occasionally I get thrown this exception when saving my png:

SysError(Can't read C:/mygame/assets/gfx/terrains/grasslands.png)

Called from sys.io.$File.getBytes (C:\HaxeToolkit\haxe\std/hl/_std/sys/io/File.hx line 42)
Called from hxd.fs._LocalFileSystem.LocalEntry.getBytes (hxd/fs/LocalFileSystem.hx line 55)
Called from hxd.res.Image.getPixels (hxd/res/Image.hx line 109)
Called from local function #3789 (hxd/res/Image.hx line 231)
Called from hxd.res.Image.loadTexture (hxd/res/Image.hx line 240)
Called from h3d.impl.DirectXDriver.uploadBuffers (h3d/impl/DirectXDriver.hx line 1055)
Called from h3d.impl.DirectXDriver.uploadShaderBuffers (h3d/impl/DirectXDriver.hx line 974)
Called from h3d.Engine.uploadShaderBuffers (h3d/Engine.hx line 116)
Called from h3d.pass.Default.draw (h3d/pass/Default.hx line 161)
Called from h3d.scene.DefaultRenderer.renderPass (h3d/scene/DefaultRenderer.hx line 73)
Called from h3d.scene.DefaultRenderer.render (h3d/scene/DefaultRenderer.hx line 86)
Called from h3d.scene.Renderer.process (h3d/scene/Renderer.hx line 175)
Called from h3d.scene.Scene.render (h3d/scene/Scene.hx line 408)
Called from hxd.App.render (hxd/App.hx line 97)
Called from h3d.Engine.render (h3d/Engine.hx line 386)
Called from hxd.App.mainLoop (hxd/App.hx line 165)
Called from hxd.$System.mainLoop (hxd/System.hl.hx line 70)
Called from hxd.$System.runMainLoop (hxd/System.hl.hx line 125)
Called from hxd.$System.runMainLoop (hxd/System.hl.hx line 122)
Called from local function #3172 (C:\HaxeToolkit\haxe\std/haxe/Timer.hx line 140)
Called from local function #3173 (C:\HaxeToolkit\haxe\std/haxe/Timer.hx line 74)
Called from haxe.$MainLoop.tick (C:\HaxeToolkit\haxe\std/haxe/MainLoop.hx line 166)
Called from haxe.$EntryPoint.processEvents (C:\HaxeToolkit\haxe\std/haxe/EntryPoint.hx line 104)
Called from haxe.$EntryPoint.run (C:\HaxeToolkit\haxe\std/haxe/En

I presume it’s because my graphics editor sometimes hasn’t finished writing the file yet. And when I keep running, the texture updates just fine the next render loop or so.

Now my questions are: Is there a more elegant solution to reloading the data?
Am I missing something? I feel like there should be a save check if a file is being written to currently while live reloading.

Also: While the png reload works fine, I can not get changes to my fbx file to show up. I guess this is because of the way the ModelCache works? But how would I go about reloading my fbx data?

Okay, so I just watched the really, really helpful “Making games with Heaps.io” presentation and it seems this is already a known issue :wink:

Still would be good to know if there is a known workaround…

From the video I also understand the fbx -> hmd workflow a lot better now.
I got the fbx live reloading working in principle by regenerating the hmd cache like so:

function reload()
{
    s3d.removeChild(obj);
    cache.dispose();

    hxd.Res.initLocal();

    obj = cache.loadModel(hxd.Res.gfx.terrains.plane);
    s3d.addChild(obj);
}

It’s not very elegant but for now I can work from there!

1 Like

I’ve opened an issue for it there: https://github.com/HeapsIO/heaps/issues/452