hlimgui icon indicating copy to clipboard operation
hlimgui copied to clipboard

Can't build out/main.c

Open mrpierrot opened this issue 2 years ago • 9 comments

Hi ! Thank you for the update of the Dear ImGui port. It's really cool. That work great when I build a .hl file that not compile when I tried to native code (For Windows)

My setup :

  • the file hlimgui.hdll at the root of my project

  • build.directx.dist.hxml (the hxml use to generate native code) :

-cp src
-lib heaps
-lib hldx
-lib json2object
-main game.Boot
-D windowSize=1280x720
-D RES_PAK
-D no-deprecation-warnings
-hl out/main.c

imgui hx files copied in my source folder image

When I run haxe .\build.directx.dist.hxml

I have the following error : Invalid_argument("output_value: functional value")

Can you help me for this issue ?

Thank you.

mrpierrot avatar Sep 17 '23 12:09 mrpierrot

Originally I thought this was https://github.com/HaxeFoundation/haxe/issues/9803

However, it seems we have a slightly different variant of this bug. We're not passing refs through non-extern functions, but we do pass refs to Strings (eg ImGui.inputText), and these trigger this error reliably. I verified it wasn't the callback (removing it from the function signature doesn't help), simply changing the type to be an Int ref instead instantly clears the build error (though obviously this doesn't actually solve the problem).

Simple test case:

class Main {
	static function main() {
		var test: String = "";
		ImGui.inputText( "label", test );
	}
}

produces Invalid_argument("output_value: functional value"). However inputInt for example is fine.

Not sure there's a path forward on our end. @Yanrishatum might have some additional knowledge but I'm fairly sure this is a haxe/hashlink bug unfortunately.

If you're not using any string refs you might be able to dodge it with -dce full for now but... that's not really a solution. I'd suggest filing a bug there and using hl bytecode for now, which is well tested with hlimgui.

nspitko avatar Sep 17 '23 21:09 nspitko

Thank you @nspitko

In fact with -dce full option, that build correctly (and calling ImGui.showDemoWindow();) Infortunatly for me, I encounter an other error when I build the c generated code in exe. I could test how the xe with ImGui run later. But that's another story.

Where I can fill a bug report to advance in the resolution of that bug ?

Thank you.

mrpierrot avatar Sep 18 '23 12:09 mrpierrot

I've gone ahead and submitted it: https://github.com/HaxeFoundation/haxe/issues/11313

nspitko avatar Sep 20 '23 04:09 nspitko

I have the same issue, is there any way to build the C code or a workaround that is viable?

SanBen avatar Jan 12 '24 16:01 SanBen

There are a few options

  1. Don't use (or remove if you're not using DCE) inputText or any similar function that takes a ref to a string.
  2. Change these functions to pass bytes instead. There will be a perf hit for the conversion but it's probably not significant.
  3. Don't use hl/c.

The last option is... probably the best unless you have a strong need for it. Last I checked none of the games the primary heaps developer shipped use hl/c, the main value is just the ability to ship on platforms where the hlvm doesn't yet (or can't) work.

nspitko avatar Jan 12 '24 19:01 nspitko

There are a few options

1. Don't use (or remove if you're not using DCE) `inputText` or any similar function that takes a ref to a string.

2. Change these functions to pass bytes instead. There will be a perf hit for the conversion but it's probably not significant.

3. Don't use hl/c.

The last option is... probably the best unless you have a strong need for it. Last I checked none of the games the primary heaps developer shipped use hl/c, the main value is just the ability to ship on platforms where the hlvm doesn't yet (or can't) work.

I was under the impression that Dead Cells was using hl/c to improve performance and the docs hint at better performance also.

Initial benchmark shows that HL/JIT outperforms Adobe AIR and Node/V8 in many cases. Many room for performance improvement exists in HL/JIT to bring it as much near as HL/C as possible.

However, maybe I misunderstood.

So the best way to make a release is to bundle hashlink with the JIT Code? https://gist.github.com/Yanrishatum/d69ed72e368e35b18cbfca726d81279a?permalink_comment_id=3506077#bundle-hashlink-with-the-game

SanBen avatar Jan 12 '24 22:01 SanBen

That's Motion Twin, I was referring to Shiro Games (run by Cannasse). You'll find a hlboot.dat in, for example, Northgard.

I'm not asserting hl/c isn't faster than hl JIT, but the perf is close enough that it probably won't matter for the things you'd typically want imgui for.

If your needs are different, the other solutions should work, or just explain your use case better. For what it's worth, I strip imgui out of my rel builds.

nspitko avatar Jan 12 '24 23:01 nspitko

This should be fixed under haxe nightly, but leaving this open until someone can verify

nspitko avatar Sep 05 '24 08:09 nspitko

I had it in my todo. Thank you.

mrpierrot avatar Sep 05 '24 09:09 mrpierrot