On Sun, Feb 21, 2016 at 11:27 PM, George Corney <haxio...@gmail.com> 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
GetIndexedPropertiesExternalArrayData() is the wrong approach if you plan on upgrading someday - it was removed in V8 3.29. In your case, I'd use GetContents() coupled with a Persistent<ArrayBuffer> for keeping the arraybuffer object alive until you're done with it. If GetContents() doesn't exist in the version of V8 you're using, upgrade. That's a good idea anyway because the 3.28 branch is retired, the last update was in 2014. -- -- v8-users mailing list v8-users@googlegroups.com 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 v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.