xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
694 stars 279 forks source link

Spinner - using a custom spinner result in getting a lost dom element #1524

Open de-buddy opened 3 weeks ago

de-buddy commented 3 weeks ago

Describe the bug

While using the viewer, we use a custom spinner.

But this dom element can get lost/destroyed.

The reason in (dist/xeokit-sdk.es.js Line: 15060....): ´this._isCustom = false;seems to be always false. When_destroy()` is called internally,

Line 15190...
_destroy() {
    if (this._element && (!this._isCustom)) {
              //                 ^^^^^^ custom was used but here never set to something positive. Its always false
              // remove element: in this case also our custom spinner:
        this._element.parentNode.removeChild(this._element);
        this._element = null;
    }
    ...

eg. when re-init the viewer like viewer.destroy(); it drops our custom dom element e.g: <div id="myspinner"...

The next creation of a viewer can not find myspinner in the dom anymore and creates an internal spinner we can not control (in position or layout).

To Reproduce

viewer = new Viewer({
    canvasElement: viewerCanvas,
    transparent: true
    spinnerElementId: "myspinner"
}),

// ... load model/s an show

if (viewer) { 
    viewer.destroy();
}

// create a new viewer
viewer = new Viewer({
    canvasElement: viewerCanvas,
    transparent: true
    spinnerElementId: "myspinner"
}),
ERROR:
    [Spinner '__1']: Can't find given Spinner HTML element: 'myspinner' - will automatically create default element

Desktop (please complete the following information):

Kind regards