mpetroff / pannellum

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

Potential Incomplete Destroy #506

Open campbellhennessy opened 6 years ago

campbellhennessy commented 6 years ago

I have an application where I need to reload the scenes list from time to time in tour mode. From what I've found it isn't natively supported so to do this I call the destroy method on the viewer and rebuild a new viewer object. After a number of destroys I was noticing a slow down so I checked the event log. After a bit of testing it I noticed that there are events that seem to increase in number based on the number of destroys (ie show up as an individual recurring event on page load, after one destroy and rebuild then I see the events in groups of two, and increasing linearly as I destroy and rebuild). The events come from:

setTimeout(processNextTile, 0, program.currentNodes[i]); in libpannellum.js

and

else if (renderer && (renderer.isLoading() || (config.dynamic === true && update))) {
        requestAnimationFrame(animate);
    }

in pannellum.js

In my code I am calling viewer.destroy() for a viewer created with viewer = pannellum.viewer(elem, config).

I'm not sure if this is an issue or if it is just me going about this the wrong way (or indeed trying to do something that is not supported). Is there anything I could do in my code to eliminate this behaviour?

mpetroff commented 6 years ago

I'll need to take a closer look, but it's very likely that these events are due to bugs.

While reloading the scene list directly isn't supported, you could loop through the scene list retrieved via getConfig and call removeScene on each one. You could then loop through your new scene list and call addScene for each new scene.