BabylonJS / BabylonNative

Build cross-platform native applications with the power of the Babylon.js JavaScript framework
MIT License
769 stars 132 forks source link

Napi ArrayBuffer constructor behaves inconsistently with undefined #1118

Open CoPrez opened 2 years ago

CoPrez commented 2 years ago

While testing out the BaseTexture::readPixels() function I found that the behavior of the Napi ArrayBuffer construction at this line was behaving differently in Babylon Native vs Babylon React Native where the implementations of Napi differ.

In Babylon Native the ArrayBuffer construction works as expected and later on IsNull() on the buffer returns true. In Babylon React Native an exception is thrown at that line and the readPixels operation is aborted.

To Reproduce Steps to reproduce the behavior:

  1. In the Babylon React Native playground call readPixels() on a texture with no arguments

Expected behavior The call to readPixels() succeeds

Screenshots If applicable, add screenshots to help explain your problem.

Other Tested on React-Native Android

bghgary commented 2 years ago

I tested this with V8 (reference), Chakra, and JSI using the following code:

        auto arg = info[0];
        auto arrayBuffer = arg.As<Napi::ArrayBuffer>();

        auto argIsNull = arg.IsNull();
        (void)argIsNull;

        auto arrayBufferIsNull = arrayBuffer.IsNull();
        (void)arrayBufferIsNull;

V8: argIsNull is true, arrayBufferIsNull is true Chakra: argIsNull is true, arrayBufferIsNull is false JSI: argIsNull is true, arrayBufferIsNull causes assert

These should all be the same.