Deno SDL2 Default Text Render Example (FFI problem w 1.29)
Trying to get the font render example in the Deno SDL2 repo https://github.com/littledivy/deno_sdl2/blob/main/examples/font/font.ts to work but it perpetually complains about a pointer to buffer issue.
I've read through the issues that were proposed to fix this solution and tried modifications of my own to solve this issue based on this PR here https://github.com/littledivy/deno_sdl2/pull/58 but the issue still remained in my own modifications. Wondering if anybody has any ideas on how to resolve this as it pertains specifically to FFI problems which I thought would be resolved in Deno 1.29 since that seemed to caused breaking changes.
I've already tried the v3 released of SDL2 and it did not resolve the problem either. I have a large and mature project I want to port over to desktop but cannot use this solution until I can draw font. I am not seeking alternative solutions such as Electron :)
Error:
GitHub
deno_sdl2/font.ts at main · littledivy/deno_sdl2
SDL2 module for Deno. Contribute to littledivy/deno_sdl2 development by creating an account on GitHub.
GitHub
update Deno to upcoming 1.29 by littledivy · Pull Request #58 · lit...
Fixes #55
Fixes #57
Fixes #54
17 Replies
What's the exact error?
Forgot to include:
@aapoalas
You can read a similar error here which could be resolved by changing the expected parameter to "buffer" instead of "pointer" but making those changes for the font render doesn't resolve the error for me
https://github.com/littledivy/deno_sdl2/issues/55
GitHub
Uncaught TypeError: Invalid FFI pointer type, expected null, intege...
Trying to run the hello.ts example, but getting an error, pasted below. This happens on multiple machines on the latest deno. The most recent version of deno I have laying around where the code wor...
This would be the code I'm working out of
You can see the relevant section its failing on here
Catch the error, check parameters. It seems like the code is probably being called with a pointer number somewhere.
Okay, I wrapped it in try catch and added additional logging around the function it goes into
How can I identify a pointer in JS?
Must be the this[_raw] since thats a Deno.UnsafePointer
I tried to cast it as an array buffer but it said allocation failed
Error
Very bad because that means it cant allocate enough
Could be either the this[_raw] or the Color since that might be being passed in as a pointer. Casting both using the asCString did not fix, nor did changing the type expectations in the relevant section
Tried casting color and the pointer to BigInt and tried using TextEncoder but no change
https://stackoverflow.com/questions/61813646/whats-deno-equivalent-of-node-js-buffer-fromstring
Stack Overflow
What's Deno equivalent of Node.js Buffer.from(string)
How can I convert a string to a buffer?
I tried: Uint8Array.from('hello world') but it isn't working
I've seen this so many I can try to adjust it
I've changed every value in here to null and identified the text as the problem it seems
This will atleast not result in an error
Okay so this
with
is acceptable and doesn't error out
Now just to figure out how to draw a rect in SDL and copy the texture to it so its predictable
Good that you got it figured out. The logging here shows that the first and third parameters are indeed numbers (pointer) and not buffers, so that was the issue as you found out.
The
asCstring
method will probably automatically add a null character at the end of your string, whereas doing a direct encode()
does not and will probably eventually lead to the native code reading beyond the bounds of your string buffer.
Better to use the asCstring
helper method.I did the encode and it did remove the null character but I see that as a serious concern. How then, can one draw font without those characters in a cross platform way? Also it did kinda seem that playing with the encoding of the test made the color application not stick to the font consistently
By adding the null character.
Encode
'${string}\0'
or just use the asCstring
helper which does that for youInteresting. Will try again tomorrow and see what it does
It will essentially just make the resulting
Uint8Array
1 byte longer.
eg. above your "Hello there!" logged:
With a direct encode it'd log
So, you're just missing the singlar null byte from the end.I see. That seemed to resolve it.
Still have inconsistent color results which is really odd