node-sdl icon indicating copy to clipboard operation
node-sdl copied to clipboard

Bun support

Open Thunderducky opened this issue 1 year ago • 6 comments

I tried running the base examples with bun and got segmentation errors when calling window.render. I suspect it's related to differences in how the buffer is handled.

If there is a way around this/workaround that'd be great!

Thunderducky avatar Sep 08 '23 22:09 Thunderducky

@Thunderducky I'd like to support bun eventually, but right now their support for napi modules is not even finished (https://github.com/oven-sh/bun/issues/158) and I am encountering too many weird bugs when trying to run the examples. I'd suggest leaving the issue open and I'll revisit it as bun becomes more stable in the future.

kmamal avatar Sep 09 '23 22:09 kmamal

Thank you! Love the library

Thunderducky avatar Sep 11 '23 16:09 Thunderducky

I could run a small example with bun

// index.js
import sdl from '@kmamal/sdl'

// Setup
const window = sdl.video.createWindow({ title: "Canvas" })
window.setFullscreen(true);
const { pixelWidth: width, pixelHeight: height } = window
const buffer = Buffer.alloc(width * height * 4).fill(0);
for (let n = 0; n < buffer.length; n += 4) {
    const i = Math.floor(n / (4 * width));
    const j = Math.floor((n / 4) % width);
    const x = j;
    const y = height - 1 - i;
    buffer[n] = Math.min(255, (x / width) * 255);
    buffer[n + 1] = Math.min(255, (y / height) * 255);
    buffer[n + 2] = 0;
    buffer[n + 3] = 255;
}
console.log("debug ", buffer)
window.render(width, height, width * 4, 'rgba32', buffer);

Then ran bun index.js, with bun version 1.0.28.

Great lib btw, thank you @kmamal

pedroth avatar Mar 03 '24 11:03 pedroth

Oh interesting, time to have another look then.

kmamal avatar Mar 03 '24 12:03 kmamal

Just a note here about using bun to install node-sdl:

https://github.com/oven-sh/bun/issues/9220

One needs to add node-sdl as a trustedDependencies, for bun to install.

@Thunderducky @kmamal

pedroth avatar Mar 05 '24 12:03 pedroth

Linking this issue so I can track it easier: https://github.com/oven-sh/bun/issues/9743

kmamal avatar Mar 30 '24 21:03 kmamal