{"action":"opened","issue":{"url":"https://api.github.com/repos/electron/electron/issues/7732","repository_url":"https://api.github.com/repos/electron/electron","labels_url":"https://api.github.com/repos/electron/electron/issues/7732/labels{/name}","comments_url":"https://api.github.com/repos/electron/electron/issues/7732/comments","events_url":"https://api.github.com/repos/electron/electron/issues/7732/events","html_url":"https://github.com/electron/electron/issues/7732","id":185142988,"number":7732,"title":"Native module crashes renderer but not main process","user":{"login":"iglosiggio","id":1154680,"avatar_url":"https://avatars.githubusercontent.com/u/1154680?v=3","gravatar_id":"","url":"https://api.github.com/users/iglosiggio","html_url":"https://github.com/iglosiggio","followers_url":"https://api.github.com/users/iglosiggio/followers","following_url":"https://api.github.com/users/iglosiggio/following{/other_user}","gists_url":"https://api.github.com/users/iglosiggio/gists{/gist_id}","starred_url":"https://api.github.com/users/iglosiggio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iglosiggio/subscriptions","organizations_url":"https://api.github.com/users/iglosiggio/orgs","repos_url":"https://api.github.com/users/iglosiggio/repos","events_url":"https://api.github.com/users/iglosiggio/events{/privacy}","received_events_url":"https://api.github.com/users/iglosiggio/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-25T14:58:32Z","updated_at":"2016-10-25T14:58:32Z","closed_at":null,"body":"* Electron version: v1.4.0\r\n* Operating system: Huayra Linux\r\n    - Kernel: Linux huayra 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux\r\n\r\nUsing v4l2camera (for managing webcams, and using their advanced controls like exposure) crashes the renderer process when it's GC'ing.\r\n\r\nLog:\r\n```\r\n[3702:1025/111503:FATAL:PartitionAlloc.cpp(957)] Check failed: page->numAllocatedSlots != -1. \r\n#0 0x000001e3f38e <unknown>\r\n#1 0x000001e5508b <unknown>\r\n#2 0x000002567029 <unknown>\r\n#3 0x00000258999d <unknown>\r\n#4 0x7f751d30c153 v8::internal::ArrayBufferTracker::ProcessBuffers()\r\n#5 0x7f751d30c026 v8::internal::ArrayBufferTracker::FreeDeadInNewSpace()\r\n#6 0x7f751d318a87 v8::internal::Heap::Scavenge()\r\n#7 0x7f751d315d13 v8::internal::Heap::PerformGarbageCollection()\r\n#8 0x7f751d3153ce v8::internal::Heap::CollectGarbage()\r\n#9 0x7f751d35a0cc v8::internal::ScavengeJob::IdleTask::RunInternal()\r\n#10 0x0000005800f1 <unknown>\r\n#11 0x000000580434 <unknown>\r\n#12 0x00000057fa9a <unknown>\r\n#13 0x00000057fde4 <unknown>\r\n#14 0x000001e40056 <unknown>\r\n#15 0x000000579197 <unknown>\r\n#16 0x0000005782b9 <unknown>\r\n#17 0x000001e40056 <unknown>\r\n#18 0x000001e5b585 <unknown>\r\n#19 0x000001e5b878 <unknown>\r\n#20 0x000001e5bccb <unknown>\r\n#21 0x000001e5d0aa <unknown>\r\n#22 0x000001e7424e <unknown>\r\n#23 0x000001e5acca <unknown>\r\n#24 0x0000013ab40c <unknown>\r\n#25 0x00000120840d <unknown>\r\n#26 0x000001209507 <unknown>\r\n#27 0x000001207fe0 <unknown>\r\n#28 0x000003460343 main\r\n#29 0x7f751618ab45 __libc_start_main\r\n#30 0x000000562299 <unknown>\r\n```\r\n\r\nRelated v8 file: [PartitionAlloc.cpp:957](https://chromium.googlesource.com/chromium/blink.git/+/master/Source/wtf/PartitionAlloc.cpp#961)\r\n\r\nThe crash only happens if the renderer process gets a frame (Uint8Array) that stays on the heap an has to be GC'ed (well, at least that's my hypothesis).\r\n\r\nWhen runing this code con the ``main`` context everything works.\r\n\r\n##Example code for the renderer\r\n\r\n```js\r\ncam = require('v4l2camera').Camera('/dev/video0');\r\ncam.start();\r\ncam.capture(function loop() { cam.capture(loop); });\r\n\r\ncanvas = document.createElement('canvas');\r\ncanvas.width = 640;\r\ncanvas.height = 480;\r\n\r\ndocument.body.appendChild(canvas);\r\n\r\nc2d = canvas.getContext(\"2d\");\r\nimgdata = c2d.createImageData(640, 480)\r\n\r\nfunction draw(screen) {\r\n  for(var i = 0; i < 640 * 480; i++) {\r\n    imgdata.data[i * 4 + 0] = screen[i * 3 + 0];\r\n    imgdata.data[i * 4 + 1] = screen[i * 3 + 1];\r\n    imgdata.data[i * 4 + 2] = screen[i * 3 + 2];\r\n    imgdata.data[i * 4 + 3] = 255\r\n  }\r\n  c2d.putImageData(imgdata, 0, 0);\r\n}\r\n\r\nsetInterval(function drawImage() {\r\n  draw(cam.frameRaw());\r\n}, 30);\r\n\r\n// The image might seem buggy according to your webcam  internal format :P\r\n// Wait some time and enjoy the crash! (or cry like i do :( )\r\n```\r\n\r\n## Example code for the main context (stolen from [v4l2camera examples](https://github.com/bellbind/node-v4l2camera/blob/master/examples/yuyv-stream-server.js))\r\n```js\r\nvar http = require(\"http\");\r\nvar v4l2camera = require(\"v4l2camera\");\r\n\r\nvar script = function () {\r\n    window.addEventListener(\"load\", function (ev) {\r\n\t\tvar rgb2rgba = function (rgb, rgba, width, height) {\r\n\t\t    for (var i = 0; i < width * height; i++) {\r\n\t\t\t\trgba[i * 4 + 0] = rgb[i * 3 + 0];\r\n\t\t\t\trgba[i * 4 + 1] = rgb[i * 3 + 1];\r\n\t\t\t\trgba[i * 4 + 2] = rgb[i * 3 + 2];\r\n\t\t\t\trgba[i * 4 + 3] = 255;\r\n\t\t    }\r\n\t\t    return rgba;\r\n\t\t};\r\n\t\tvar cam = document.getElementById(\"cam\");\r\n\t\tvar c2d = cam.getContext(\"2d\");\r\n\t\tvar image = c2d.createImageData(cam.width, cam.height);\r\n\t\r\n\t\t(function load() {\r\n\t\t    var req = new XMLHttpRequest();\r\n\t\t    req.responseType = \"arraybuffer\";\r\n\t\t    req.addEventListener(\"load\", function (ev) {\r\n\t\t\t\tvar rgb = new Uint8Array(req.response);\r\n\t\t\t\trgb2rgba(rgb, image.data, image.width, image.height);\r\n\t\t\t\tc2d.putImageData(image, 0, 0);\r\n\t\t\t\tsetTimeout(load, 10);\r\n\t\t    }, false);\r\n\t\t\treq.open(\"GET\", \"/\" + Date.now() + \".yuv\", true);\r\n\t\t\treq.send();\r\n\t\t})();\r\n    }, false);\r\n};\r\n\r\nvar cam = v4l2camera.Camera(\"/dev/video0\")\r\ncam.start();\r\ncam.capture(function loop() {\r\n\tcam.capture(loop);\r\n});\r\n\r\n\r\nvar server = http.createServer(function (req, res) {\r\n\tif (req.url === \"/\") {\r\n\t\tres.writeHead(200, {\r\n\t\t\t\"content-type\": \"text/html;charset=utf-8\",\r\n\t\t});\r\n        res.end([\r\n\t\t\t\"<!doctype html>\",\r\n\t\t\t\"<html><head><meta charset='utf-8'/>\",\r\n\t\t\t\"<script>\",\r\n\t\t\t\"(\" + script.toString() + \")()\",\r\n\t\t\t\"</script>\",\r\n\t\t\t\"</head><body>\",\r\n\t\t\t\"<canvas id='cam' width='640' height='480' />\",\r\n\t\t\t\"</body></html>\",\r\n\t\t].join(\"\\n\"));\r\n\t\treturn;\r\n\t}\r\n\tif (req.url.match(/^\\/.+\\.yuv$/)) {\r\n\t\tvar buf = Buffer(cam.frameRaw());\r\n\t\tres.writeHead(200, {\r\n\t\t\t\"content-length\": buf.length\r\n\t\t});\r\n\t\tres.end(buf);\r\n\t}\r\n});\r\n\r\nserver.listen(3000);\r\n\r\n// Now go to localhost:3000 an look at your camera :P\r\n```\r\n\r\nAnd yes, if this works it's normal that this hacky code could lead to results like these \r\n![Cam looking weird](https://cloud.githubusercontent.com/assets/1154680/19691232/eee952bc-9aa9-11e6-92cd-6ebafffdd609.png)\r\n**But this is _working_** (i can retrieve the raw frame w/o crashing everything :P)\r\n\r\nAny help on how to track down the source of the bug? It may be the module, v8 or electron.\r\n"}}
{"actor":{"display_login":"iglosiggio"}}