tonyb486 / stlviewer

A Simple STL Viewer with Three.js
27 stars 6 forks source link

Error on using STL viewer multiple times on same page. #1

Closed moxajogani closed 3 years ago

moxajogani commented 3 years ago

I am getting WARNING: Too many active WebGL contexts. Oldest context will be lost. error in console and the model is not displayed when I am trying to display multiple models on single page.

tonyb486 commented 3 years ago

Hmm, it works for me when I try this code:

https://gist.github.com/tonyb486/37f322d74373b2a166a0e0e7315ec7a4

Or this code, with two divs of the same class:

https://gist.github.com/tonyb486/5258940a278c8fff5620dd378a018ed9

Anything you are doing differently?

Tested it on FF and Safari on macOS, Safari on iOS, and FF, Chrome, and Edge on Windows...

moxajogani commented 3 years ago

No, I have a for loop called on document load which for displaying more than 10 STL Viewers on a single page. It works fine if I use it for 2 or 3 models.

I have attached the code which I am using. 3dviewer.zip

tonyb486 commented 3 years ago

Don't apply the viewer to the same HTML element multiple times.

Try something like this, maybe: https://gist.github.com/tonyb486/d7fac86018fe23ff2769b45b2111fd7e/revisions

(untested, but hopefully you get the idea)

moxajogani commented 3 years ago

Hi Tony,

Thank you for the updated code.

I have modified the code as per the guidelines you have given, but I am still facing the issue whenever I run the STLViewer function in a for loop.

I have attached the modified code.

3dviewer.zip

moxajogani commented 3 years ago

One more thing, I am getting this error above 15 STL viewers on a single page.

Can you please let me know if there is a way to increase the limit programatically?

tonyb486 commented 3 years ago

Ah, I don’t think so. It’s a hard limit written into the browser.

https://threejsfundamentals.org/threejs/lessons/threejs-multiple-scenes.html