openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
749 stars 361 forks source link

[cpp-windows] Lime randomly fails to preload the `default` asset library #1725

Closed UncertainProd closed 8 months ago

UncertainProd commented 8 months ago

This seems to happen randomly when I try building for windows, where the code compiles but when the application starts it gives the follwing error: image

Lime Version: 8.1.1 Hxcpp Version: 4.3.2

Steps to reproduce: It doesn't happen consistently but for any given lime project if it does happen once then it happens on every re-compilation (even if you run lime clean windows and re-compile) I used the command lime create HelloWorld <my-test-project-name> to create the project, and the code I used is in the zip file below: Testing3DStuff2.zip Upon building and running with lime test windows -debug, it gives me the above error.

Additionally, if I move the generated "bin/" directory to a different location, then the executable works without any problems, which was pretty weird.

Video showcasing the compilation:

https://github.com/openfl/lime/assets/83609901/cc6f344b-c7b3-4d72-ba19-21f5d4d642a5

This only seems to happen when compiling to windows, I tested with html5 and it worked perfectly fine

UncertainProd commented 8 months ago

I did a bit of digging around in the source code and it looks like the path to the manifest/default.json file seems to be mysteriously getting shortened by the SDL_GetBasePath function (It should be C:\Users\......\Export\windows\bin\, but SDL_GetBasePath returned C:\Users\......\Export\windows\. This seems to be related to https://github.com/libsdl-org/SDL/issues/4439 (this also explains why my exe file suddenly worked when I moved it up one directory) This issue was fixed by https://github.com/libsdl-org/SDL/pull/4437 . But it looks like the SDL submodule that lime uses is from before that PR was merged. So I'm guessing a submodule update should fix this issue.

player-03 commented 8 months ago

Good to know.

Can you try with the 8.2.0-Dev branch? That uses more recent versions of the submodules.

UncertainProd commented 8 months ago

That seems to fix the issue, thanks! But now after I compile I get this on the console:

Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)
Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)

Although the program itself runs just fine and doesn't crash

Edit: Just noticed that the final application seems to be missing it's default lime icon now

player-03 commented 8 months ago

Don't know about the icon, but check if adding -eval fixes the compile-time errors.

UncertainProd commented 8 months ago

Yes, adding -eval seems to fix those errors

player-03 commented 8 months ago

Then in theory, lime rebuild cpp should also fix them. ...But it should also have been required to fix the SDL error, so I'd assumed you'd done it.

UncertainProd commented 8 months ago

I had used lime rebuild windows cuz the readme said so. Is it different from lime rebuild cpp?

player-03 commented 8 months ago

It's the same. I always say cpp to save myself the trouble of asking what system someone uses.

Hmm. Did you do git submodule sync and git submodule update?

UncertainProd commented 8 months ago

I used git clone --recursive while cloning and then ran git submodule update. I just tried to run git submodule sync now and then tried to rebuild but the same error shows up

player-03 commented 8 months ago

Oh wait, get_num_trackballs was removed, not added. Maybe all you need is lime rebuild tools.

UncertainProd commented 8 months ago

I tried it now but the same error shows up

player-03 commented 8 months ago

Maybe lime rebuild tools -clean? I don't know what else it would be.

UncertainProd commented 8 months ago

No, same issue. Just to be sure, I tried using both lime test ... and haxelib run lime test ... but neither seem to fix it

player-03 commented 8 months ago

Well, maybe double-check haxelib path lime to make sure it's the repo you just cloned. And try moving the old directory, so that it can't accidentally use any of the files from there.

UncertainProd commented 8 months ago

Hi, sorry for the delay. I checked haxelib path lime and it does point to the newly cloned repo. I tried moving the old one and the issue still happens. According to the error message, the problem seems to happen at line 686 in NativeCFFI.hx:

Called from lime/_internal/backend/native/NativeCFFI.hx line 686
Called from lime/system/CFFI.hx line 111
Called from C:\HaxeToolkit\haxe\std/neko/Lib.hx line 35
Uncaught exception - load.c(357) : Primitive not found : ./lime@lime_joystick_get_num_trackballs(1)

But line 686 is just this: https://github.com/openfl/lime/blob/21e8e619c36a0fed8672caae84114b4c7ee8a563/src/lime/_internal/backend/native/NativeCFFI.hx#L686

player-03 commented 8 months ago

If you go back as far as 7.9.0, you'll find that the line indeed does try to load get_num_trackballs. This suggests that one way or another, you're still using a very old version of tools.n.

Let's cover our bases here:

Failing that:

UncertainProd commented 8 months ago

I tried out your steps but the error still showed up, so I tried manually running the hxml files inside the tools folder and somehow when I rebuilt svg.n using tools/svg.hxml the error disappeared (no idea how) 🤔

player-03 commented 8 months ago

Good to know, and glad you got it figured out.

UncertainProd commented 8 months ago

Thanks for your help!

joshtynjala commented 7 months ago

I just checked GitHub Actions, and it looks like we haven't been rebuilding svg.n. We've been using a prebuilt version committed in 2019. Continuing to use this same version for multiple releases hasn't been an issue so far, since lime.ndll hasn't removed any APIs in those releases. However, 8.2.0 will need a new svg.n due to that removal of lime_joystick_get_num_trackballs.

I updated the develop branch to make GitHub Actions build svg.n for the Haxelib bundle, and this will eventually get merged into 8.2.0-Dev before the 8.2 release.