News for hackers. Stuff that matters.
Re:I built a vector map from scratch by fgeiger on Thursday August 18, 2022 @02:38PM (#32513311)
Whoa, zooming and panning too fast crashed the entirety of Firefox. All windows just gone in an instant. How is that even possible nowadays?
Re:I built a vector map from scratch by jstimpfle on Thursday August 18, 2022 @03:26PM (#32513813)
The memory consumption on FF is out of control. Just loading the app and not interacting, it's going up at 1GB per few seconds for me with no perceivable upper bound. I killed the tab before risking system instability. With Chrome I'm not seeing this behaviour - the memory is stable at around 500-600M (probably around 400M for the app).
Re:I built a vector map from scratch by kocheez75 on Thursday August 18, 2022 @03:32PM (#32513889)
Interesting, my hunch would be something about the webgl buffers not getting freed, since they’re running in a tight loop. I’ll do some digging.
Re:I built a vector map from scratch by jstimpfle on Thursday August 18, 2022 @06:53PM (#32515787)
From a quick look it seems like you're doing gl.createBuffer() in a loop each time you're drawing, and never call gl.deleteBuffer(). It seems like WebGL will call deleteBuffer() automatically when the object is garbage collected by the JS runtime, but calling it explicitly when you're done with it will probably fix this particular issue.

Also a suggestion, try to allocate your buffers only once on setup, and reuse them each time you're drawing. Just call gl.bufferData() in case you need to push new data. Don't use gl.bufferSubData() unless you come up with a clever way to avoid pipeline stalls such as maybe a rotating queue of buffers. This approach might or might not improve performance, but I see little reason not to do it.

To make this work you prbably have to create a vertex arrays object explicitly using gl.createVertexArray(). This object is used to capture the vertex attrib pointers. Call gl.bindVertexArray() before gl.enableVertexArray() and gl.vertexAttribPointer(). Later, in a simple draw you need then only call gl.useProgram() and gl.bindVertexArray(), but there is no need to bind buffers or set vertex attrib pointers.

Re:I built a vector map from scratch by kocheez75 on Thursday August 18, 2022 @10:43PM (#32517149)
I moved the createBuffer call out of the render loop, and I think the memory issues on FF should be working better (at least on FF 103).
Re:I built a vector map from scratch by jstimpfle on Friday August 19, 2022 @04:54AM (#32518804)
Can confirm the issue is solved for me.
Re:I built a vector map from scratch by kocheez75 on Thursday August 18, 2022 @06:59PM (#32515836)
Great pointers, I’ll give these a shot. Still new to this so appreciate the suggestions!
Re:I built a vector map from scratch by somishere on Thursday August 18, 2022 @06:52PM (#32515781)
Came here to say the same thing. Great article btw. Finished it with examples/js disabled :)
Re:I built a vector map from scratch by sirmoveon on Thursday August 18, 2022 @03:29PM (#32513847)
I think is memory leak of sorts because it skyrocketed until it became unstable
Re:I built a vector map from scratch by tejtm on Thursday August 18, 2022 @02:44PM (#32513367)
noting that the blinking off of FF is reproducible (not even doing anything fast)