hydra-synth / hydra

Livecoding networked visuals in the browser
https://hydra.ojack.xyz
GNU Affero General Public License v3.0
2.16k stars 264 forks source link

Using webcam on Windows crashes regl #24

Closed echophon closed 5 years ago

echophon commented 6 years ago

Hi!

When I try to run the webcam example on the latest build at: https://hydra-editor-v1.glitch.me

ie s0.initCam() src(s0).out()

The output loads for a few seconds and crashes to a black screen a few moments later. The console then starts loading the following error over & over.

regl.js:47 Uncaught Error: (regl) context lost at Function.raise (regl.js:47) at Object.REGLCommand [as draw] (regl.js:9396) at passes.forEach (output.js:196) at Array.forEach () at Output.tick (output.js:196) at HydraSynth.tick (index.js:293) at Engine. (index.js:52) at emitOne (events.js:106) at Engine.emit (events.js:184) at Engine.tick (index.js:42)

Initial Test - Reproduced on Win10 desktop, Chrome 68, GTX1070, dual 2560x1440 144Hz resolution monitors (one rotated to portrait) and this model of webcam https://www.amazon.com/ELP-2-8-12mm-Varifocal-1-3megapixel-Android/dp/B01N8YH5VY

The error can be cleared by refreshing but fails again a few seconds after initCam()

Test 2 - cannot repro with same webcam attached to older MBP with Nvidia card. also on Chrome 68. This should rule out the camera as cause.

Test 3 - 144Hz is only supported over displayport, & one of my screens is connected via HDMI and runs instead at 60Hz. Unable to repro on the screen that runs at 60Hz. So it appears that it is the increased frequency at 144Hz that is the culprit.

I think the cam only support 24 or 30 fps, so I suspect some sort of timing discrepancy as the root cause.

ojack commented 6 years ago

@echophon how interesting. What is the very first error that appears before all the regl errors?

Do both of these examples work with your camera+screen configuration?: https://webrtc.github.io/samples/src/content/getusermedia/gum/ https://webrtc.github.io/samples/src/content/getusermedia/canvas/

echophon commented 6 years ago

I only see a warning once, then all these errors. The warning is:

WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost

If I reevaluate the code once this occurs I see this in the canvas error handling area:

Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'.

I was able to reproduce this on the 60Hz screen, so it might not be screen related after all.

I can run both of those WebRTC samples and others (great resource) for extended periods at a time. I can also run them at the same time as Hydra and they keep working if in seperate windows. They do however blank to white when this crash occurs, but as soon as I give their window focus again they start working again. Hmmm....

ojack commented 5 years ago

@echophon any updates on this?

echophon commented 5 years ago

@ojack Applied the latest graphic drivers from NVIDIA, but still running into this. Additionally, I tried in atom-hydra & with a different webcam. In both cases, I was able to capture a bit more of the crash data into the console. Looks like a memory leak, but I found this reference on regl https://github.com/regl-project/regl/issues/430 which points to buffer allocation.

Webcam 1 WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost index.html:1 [.Offscreen-For-WebGL-0000020DD7806550]GL ERROR :GL_OUT_OF_MEMORY : BackFramebuffer::Destroy: <- error from previous GL command C:\Users\echophon.atom\packages\atom-hydra\node_modules\regl\dist\regl.js:48 Error: (regl) context lost at Function.raise (C:\Users\echophon.atom\packages\atom-hydra\node_modules\regl\dist\regl.js:47) at Object.REGLCommand [as draw] (C:\Users\echophon.atom\packages\atom-hydra\node_modules\regl\dist\regl.js:9403) at passes.forEach (C:\Users\echophon.atom\packages\atom-hydra\node_modules\hydra-synth\src\output.js:158) at Array.forEach () at Output.tick (C:\Users\echophon.atom\packages\atom-hydra\node_modules\hydra-synth\src\output.js:158) at HydraSynth.tick (C:\Users\echophon.atom\packages\atom-hydra\node_modules\hydra-synth\index.js:301) at Engine. (main.js:216) at emitOne (events.js:116) at Engine.emit (events.js:211) at Engine.tick (C:\Users\echophon.atom\packages\atom-hydra\node_modules\raf-loop\index.js:42)

Webcam 2 [.Offscreen-For-WebGL-0000021B339D9170]GL ERROR :GL_OUT_OF_MEMORY : glFramebufferTexture2D: <- error from previous GL command index.html:1 [.Offscreen-For-WebGL-0000021B339D9170]GL ERROR :GL_OUT_OF_MEMORY : glFramebufferTexture2D: index.html:1 WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost index.html:1 [.Offscreen-For-WebGL-0000021B339D9170]GL ERROR :GL_OUT_OF_MEMORY : BackFramebuffer::Destroy: <- error from previous GL command C:\Users\echophon.atom\packages\atom-hydra\node_modules\regl\dist\regl.js:48 Error: (regl) context lost at Function.raise (C:\Users\echophon.atom\packages\atom-hydra\node_modules\regl\dist\regl.js:47) at Object.REGLCommand [as draw] (C:\Users\echophon.atom\packages\atom-hydra\node_modules\regl\dist\regl.js:9403) at passes.forEach (C:\Users\echophon.atom\packages\atom-hydra\node_modules\hydra-synth\src\output.js:158) at Array.forEach () at Output.tick (C:\Users\echophon.atom\packages\atom-hydra\node_modules\hydra-synth\src\output.js:158) at HydraSynth.tick (C:\Users\echophon.atom\packages\atom-hydra\node_modules\hydra-synth\index.js:301) at Engine. (main.js:216) at emitOne (events.js:116) at Engine.emit (events.js:211) at Engine.tick (C:\Users\echophon.atom\packages\atom-hydra\node_modules\raf-loop\index.js:42)

ojack commented 5 years ago

@echophon i found an error and updated hydra-synth, the browser, and atom verion....any difference?

echophon commented 5 years ago

I think this is fixed! My initial results at hydra-editor-v1.glitch.me are looking good. I can connect multiple USB webcams, record & playback a video (vidRecorder was also crashing for me previously), and unplug webcams without an error. In this last case, they just display the last buffer received. I'll try with atom next.

I did notice that one of the example sketches (Will's Lines) throws an error "o0.scale" is not a function, so there may be a slight backwards compatibility issue. Simple enough to fix it by updating to "src(o0).scale"

ojack commented 5 years ago

yay! i am going to close the issue then!

thats interesting because i dont think o0.scale would have ever worked ... or maybe im forgetting something