- Code: Select all
void SimpleAppRenderer::OnContextCreated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
CefRefPtr<CefV8Value> object = context->GetGlobal();
int bufsize = 256 * 256 * 4;
unsigned char* buffer = new unsigned char[bufsize];
// fill buffer
for(int i = 0; i < bufsize; ++i) {
buffer[i] = rand() & 256;
}
buffer[0] = 'd';
buffer[1] = 'e';
buffer[2] = 'a';
buffer[3] = 'd';
arrbuf_ = CefV8Value::CreateArrayBuffer(buffer, bufsize, this);
object->SetValue("arrbuf", arrbuf_, V8_PROPERTY_ATTRIBUTE_NONE);
}
My SimpleApp then loads a local index.html file containing:
- Code: Select all
<html>
<head>
<script>
function myFunction() {
var canvas = document.getElementById('image');
var ctx = canvas.getContext('2d');
var buf8 = new Uint8ClampedArray(window.arrbuf);
console.log(String.fromCharCode(buf8[0], buf8[1], buf8[2], buf8[3]));
var image = new ImageData(buf8, 256, 256);
ctx.putImageData(image, 0, 0);
}
</script>
</head>
<body>
<div>Hello world!</div>
<div><button onclick="myFunction()">Click me</button></div>
<div><canvas id="image" width="256" height="256" /></div>
</body>
</html>
Pretty simple I hope! When I run this project, I see "dead" printed to the console as expected (I've also separately confirmed that javascript sees the correct byteLength for arrbuf), but when the ctx.putImageData line gets called, the helper process crashes and the browser window goes flat gray (I've also confirmed that if instead of window.arrbuf I create a new ArrayBuffer in myFunction and pass it to putImageData it works fine). If I attach a debugger first, I get EXC_BREAKPOINT triggered inside cef_execute_process in the helper process, but no more information than that (see xcode callstack in image).
What am I doing wrong here? Or how can I debug further? Thanks! -steve