gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.08k stars 650 forks source link

There are too many active WebGL contexts on this page #726

Open caracal7 opened 2 years ago

caracal7 commented 2 years ago

A GIF or MEME to give some spice of the internet

What is wrong?

Error "There are too many active WebGL contexts on this page, the oldest context will be lost." in console while application dynamically create gpu.js instances.

Where does it happen?

Its shown as error in Safari and as warning in Chrome

How do we replicate the issue?

<html>
<head>
    <script src="gpu-browser.js"></script>
</head>
<body>
    <script>

        for(let i = 0; i < 20; i++) {
            const gpu = new GPU();

            const kernel = gpu.createKernel(function(x) {
                return x;
            }).setOutput([1]);

            console.log(i, kernel(42));

            kernel.destroy();
            gpu.destroy();
        };

    </script>
</body>
</html>

How important is this (1-5)?

2

Expected behavior (i.e. solution)

No errors in console. No possible memory leaks

Other Comments

Maybe I need to use only one instance of GPU.js across the app? But I think this is not a good.

caracal7 commented 2 years ago

Maybe this can help? https://github.com/greggman/virtual-webgl

thesunfei commented 2 years ago

Create a new canavs,then make every process use the same canvas.