Thanks for the tips I agree regarding upgrading from 3.28, unfortunately for the time being I'm stuck with it as a consequence of various trade offs (I'm using JXcore which is built on 3.28 and I can't migrate away because of time constraints)
I'm trying the externalize + weak persistent handle method, here's my code now //weak callback, frees the raw data and handle void ArrayBufferWeakCallback(const v8::WeakCallbackData<v8::ArrayBuffer, v8 ::Persistent<v8::ArrayBuffer>>& info){ Print::Debug("ArrayBufferWeakCallback fired"); void* rawData = info.GetValue()->GetIndexedPropertiesExternalArrayData(); info.GetValue().Clear(); info.GetParameter()->Reset(); free(rawData); free(info.GetParameter()); } //... v8::Local<v8::ArrayBufferView> bufferView = dataArg.As<v8::ArrayBufferView >(); size_t byteLength = bufferView->ByteLength(); size_t byteOffset = bufferView->ByteOffset(); bufferView->Buffer()->Externalize(); //create weak persistent handle with callback to above code v8::Persistent<v8::ArrayBuffer>* persistent = new v8::Persistent<v8:: ArrayBuffer>(); persistent->Reset(isolate, buffer); persistent->SetWeak<v8::Persistent<v8::ArrayBuffer>>(persistent, ArrayBufferWeakCallback); const void* rawData = bufferView->GetIndexedPropertiesExternalArrayData(); const unsigned char* bytePtr = static_cast<const unsigned char*>(rawData); glBufferData(target, byteLength, bytePtr + byteOffset, usage); REPORT_GL_ERRORS(); The callback seems to fire as expected and there's no segfaults so I think this might be the solution! Could you have a quick read to see I'm not setting myself up for failure by rolling this approach out across my code? Many thanks, George On Monday, February 22, 2016 at 7:59:15 AM UTC, Jochen Eisinger wrote: > > 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 <haxi...@gmail.com > <javascript:>> 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 >> v8-u...@googlegroups.com <javascript:> >> 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+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- -- 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.