Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

TraceLog fails with RuntimeError: null function or function signature mismatch #11

Open
stanoddly opened this issue Dec 19, 2022 · 5 comments
Labels
bug Bug with workaround which needs to be resolved anyway. workaround exists Workaround exists.

Comments

@stanoddly
Copy link
Owner

I found that LoadingVox example doesn't work, it kabooms on the TraceLog function call:

TraceLog(TraceLogLevel.LOG_WARNING, $"[{voxFileNames[i]}] File loaded in {t1 - t0} ms");
INFO: RLGL: Default OpenGL state initialized successfully
dotnet.js:14 INFO: TEXTURE: [ID 11] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
dotnet.js:14 INFO: FONT: Default font loaded successfully (224 glyphs)
dotnet.js:14 INFO: FILEIO: [resources/models/vox/chr_knight.vox] File loaded successfully
dotnet.js:14 INFO: MODEL: [resources/models/vox/chr_knight.vox] VOX data loaded successfully : 2920 vertices/1 meshes
dotnet.js:14 INFO: VAO: [ID 12] Mesh uploaded successfully to VRAM (GPU)
dotnet.js:5 RuntimeError: null function or function signature mismatch

            ^^^ HERE is kaboom if you are blind or drunk

I suspect that the DllImport in Raylib-cs isn't correct. It does this:

public static extern void TraceLog(TraceLogLevel logLevel, sbyte* text);

because the TraceLog in raylib is a variadic function:

void TraceLog(int logType, const char *text, ...)

https://github.com/raysan5/raylib/blob/dbdfad7ace061931da701070c5c7fbe772c57725/src/utils.c#L107

And these two will never be good friends. 🤔

Anyway this random internet guy found that __arglist does the trick:
https://www.c-sharpcorner.com/UploadFile/b942f9/calling-unmanaged-functions-which-take-a-variable-number-of-arguments-from-C-Sharp/

What the fawk is __arglist, the totally secret C# thing?!

@stanoddly
Copy link
Owner Author

I've just try the original desktop examples and damn, it works. So maybe wasm is a bit too sensitive about the types.

image

@stanoddly
Copy link
Owner Author

And I also checked if there were some changes in TraceLog and nope, nothing happened for like 3 years already:
raysan5/raylib@343fef4

So it's very likely all about the variadic.

@stanoddly stanoddly added bug Bug with workaround which needs to be resolved anyway. workaround exists Workaround exists. labels Dec 20, 2022
@stanoddly
Copy link
Owner Author

Added workaround exists because the good ol' System.Console can be used to print something.

@chrisdill
Copy link

I think the issue also applies to TextFormat which is also missing the vardiac arguments as I couldn't get them to work correctly. Though that function can be removed if needed as it is not used much in the examples.

It might also impact custom logging though that uses a callback along with some logging utils to do the text formatting.

@chrisdill
Copy link

Though that only applies to custom logging if the other issue with callbacks is fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug with workaround which needs to be resolved anyway. workaround exists Workaround exists.
Projects
None yet
Development

No branches or pull requests

2 participants