mpetroff / pannellum

Pannellum is a lightweight, free, and open source panorama viewer for the web.
https://pannellum.org/
MIT License
4.16k stars 712 forks source link

Image continues to load after `viewer.destroy()` #1084

Closed mjau-mjau closed 2 years ago

mjau-mjau commented 2 years ago

Hi! I noticed that when calling viewer.destroy() before the panorama source image is loaded, it will continue to load in the background. Surely destroy() should abort loading the image?

In the case of creating/removing panoramas, not only does it continue to load unused images after destroy(), but when re-accessing the same panorama (src), it will cause duplicate loading of the same image. In below screenshot, I have Chrome network throttle enabled, as you can see with duplicate images loading simultaneously. To be clear, 'destroy()` works as expected, except it continues to load the panorama image src.

network inspector

I tried to see in the docs if there was any way to access the loading image, but couldn't find anything. I'm not quite sure you can easily abort image loading, but I know it can be done by removing the src attribute.

mpetroff commented 2 years ago

This was something that I never considered. I just made some changes in eb50628da1852afa5a1586f88bcd1e01a3e63468 to try to abort the image download for equirectangular and cube map images. While this appears to work in Chrome, it does not seem to have any effect in Firefox. There's also no attempt to stop multires tiles from continuing to load because making such a change would be considerably more complicated.

mjau-mjau commented 2 years ago

Thanks! Tested successfully in Chrome, and guessing it works in other webkit-browsers Edge/Safari/Opera also.

There's also no attempt to stop multires tiles from continuing to load because making such a change would be considerably more complicated.

I think the fix is mostly useful for single-source equirectangular images, which are often several MB.

Looking forward to the new version, as I will be using cdn.jsdelivr.net.