-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Issue
The current Node.js bindings for raylib have a type mismatch in the UpdateTexture / UpdateTextureRec function. The TypeScript definition forces pixel data to be a number type (presumably a pointer in C), but JavaScript/TypeScript Buffers and Uint8Arrays can't be directly passed to this function.
This makes it unnecessarily complex, forcing workarounds like writing frames to disk as PPM files before loading them back as textures.
Suggested fix
Modify the node-raylib bindings to properly handle Buffer/Uint8Array data in the functions. The C++ binding should:
Accept a JavaScript Buffer/Uint8Array directly
Extract the raw memory pointer from the Node.js buffer using something like Node's node::Buffer::Data
Pass this pointer to the raylib C function
// Updated definition to support JavaScript data types
UpdateTexture(texture: Texture, pixels: Buffer | Uint8Array | number): void;Technical implementation
In the C++ binding layer, you would need to add type checking similar to:
// In the UpdateTexture binding function
if (info[1]->IsArrayBufferView()) {
// Handle Buffer/Uint8Array case
v8::Local<v8::ArrayBufferView> view = info[1].As<v8::ArrayBufferView>();
void* data = view->Buffer()->GetContents().Data();
// Call the actual raylib function with the extracted pointer
UpdateTexture(texture, data);
} else if (info[1]->IsNumber()) {
// Handle existing number/pointer case for backward compatibility
void* data = (void*)info[1]->IntegerValue(context).FromJust();
UpdateTexture(texture, data);
}