Please note that 3.28 is a really old version of V8 which is full of known issues and no longer maintained.
In general, you'll wait to externalize the buffer and keep a weak persistent handle to the buffer - once the weak callback was triggered, you know that you can free the backing store (if you no longer need it otherwise). More current versions of V8 also have a method ArrayBufferView::CopyContents that allows you to access the backing store without externalizing the underlying buffer. On Sun, Feb 21, 2016 at 11:27 PM George Corney <[email protected]> wrote: > Hello, > > I'm working with typed arrays in v8 3.28, I've got a native function that > takes a Float32Array from javascript and passes the float* data off to a gl > call (glBufferData). > > I discovered that using just > const void* rawData = bufferView->GetIndexedPropertiesExternalArrayData(); > works, but not reliably, the data gets passes to glBufferData correctly > most of the time, but not always! > > I've found creating a persistent handle before getting the data pointer, > and then reseting handle after the glBufferData solves the problem, but is > it the right approach? Am I leaking memory / risking sending incorrect data > to glBufferData? Here's the snippet > > v8::Local<v8::ArrayBufferView> bufferView = > dataArg.As<v8::ArrayBufferView>(); > size_t byteLength = bufferView->ByteLength(); > size_t byteOffset = bufferView->ByteOffset(); > > v8::Persistent<v8::ArrayBuffer> persistent; > persistent.Reset(__contextORisolate, bufferView->Buffer()); > > const void* rawData = bufferView->GetIndexedPropertiesExternalArrayData(); > const unsigned char* bytePtr = static_cast<const unsigned char*>(rawData); > > glBufferData(target, byteLength, bytePtr + byteOffset, usage); > REPORT_GL_ERRORS(); > > persistent.Reset(); > > > ------- > > If this the wrong approach, I think the next thing is to use > bufferView->Buffer()->Externalize(); > before getting the data pointer. In this case I'm then responsible for > freeing the data - If this is necessary, could you explain how to do this? > Can it be done without altering the ArrayBufferAllocator? > > > Many thanks! > George Corney > > -- > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
