iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
591 stars 211 forks source link

Runtime error when closing iModel page (after upgrade from 4.0) #6961

Closed lijiayi0921 closed 1 month ago

lijiayi0921 commented 1 month ago

Hi,

After upgrading from 4.0 to 4.6, I'm having some issues of my itwin viewer. The imodel seems to load just fine. After I switch from iTwin page to another page(closing the page), an error appears. (error message below)

This is what I do when closing the page

    useEffect(() => {
        return () => {
            // Anything in here is fired on component unmount.
            authClient.dispose();
            IModelApp.shutdown();
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);

Chrome Error msg

ERROR
Cannot read properties of undefined (reading 'disposeTexture')
TypeError: Cannot read properties of undefined (reading 'disposeTexture')
    at Texture2DHandle.dispose (http://localhost:3001/static/js/bundle.js:221857:66)
    at dispose (http://localhost:3001/static/js/bundle.js:125879:20)
    at VertexLUT.dispose (http://localhost:3001/static/js/bundle.js:222776:69)
    at dispose (http://localhost:3001/static/js/bundle.js:125879:20)
    at PolylineGeometry.dispose (http://localhost:3001/static/js/bundle.js:211413:69)
    at dispose (http://localhost:3001/static/js/bundle.js:125879:20)
    at Primitive.dispose (http://localhost:3001/static/js/bundle.js:211563:69)
    at dispose (http://localhost:3001/static/js/bundle.js:125879:20)
    at Batch.dispose (http://localhost:3001/static/js/bundle.js:208255:69)
    at dispose (http://localhost:3001/static/js/bundle.js:125879:20)
ERROR
Unknown promise rejection reason
    at handleError (http://localhost:3001/static/js/bundle.js:775658:58)
    at http://localhost:3001/static/js/bundle.js:775681:7

Firefox Error message:

Uncaught runtime errors: ERROR _System__WEBPACK_IMPORTED_MODULE_6__.System.instance is undefined dispose@http://localhost:3001/static/js/bundle.js:221857:13 dispose@http://localhost:3001/static/js/bundle.js:125879:20 dispose@http://localhost:3001/static/js/bundle.js:222776:69 dispose@http://localhost:3001/static/js/bundle.js:125879:20 dispose@http://localhost:3001/static/js/bundle.js:211413:69 dispose@http://localhost:3001/static/js/bundle.js:125879:20 dispose@http://localhost:3001/static/js/bundle.js:211563:69 dispose@http://localhost:3001/static/js/bundle.js:125879:20 dispose@http://localhost:3001/static/js/bundle.js:208255:69 dispose@http://localhost:3001/static/js/bundle.js:125879:20 disposeContents@http://localhost:3001/static/js/bundle.js:239878:85 dispose@http://localhost:3001/static/js/bundle.js:239885:14 disposeChildren@http://localhost:3001/static/js/bundle.js:240062:19 dispose@http://localhost:3001/static/js/bundle.js:239887:14 dispose@http://localhost:3001/static/js/bundle.js:234817:15 dispose@http://localhost:3001/static/js/bundle.js:125879:20 dispose@http://localhost:3001/static/js/bundle.js:242384:69 dispose@http://localhost:3001/static/js/bundle.js:234941:15 dispose@http://localhost:3001/static/js/bundle.js:125879:20 dispose@http://localhost:3001/static/js/bundle.js:181505:86 ./node_modules/@itwin/core-frontend/lib/esm/Tiles.js/reset/<@http://localhost:3001/static/js/bundle.js:181566:56 forEach@http://localhost:3001/static/js/bundle.js:125816:17 reset@http://localhost:3001/static/js/bundle.js:181566:25 dispose@http://localhost:3001/static/js/bundle.js:181558:14 beforeClose@http://localhost:3001/static/js/bundle.js:175080:20 close@http://localhost:3001/static/js/bundle.js:169693:14 ./node_modules/@itwin/viewer-react/lib/esm/components/iModel/IModelLoader.js/IModelLoader</</<@http://localhost:3001/static/js/bundle.js:558710:37 safelyCallDestroy@http://localhost:3001/static/js/bundle.js:724045:5 commitHookEffectListUnmount@http://localhost:3001/static/js/bundle.js:724213:28 commitPassiveUnmountInsideDeletedTreeOnFiber@http://localhost:3001/static/js/bundle.js:726211:38 commitPassiveUnmountEffectsInsideOfDeletedTree_begin@http://localhost:3001/static/js/bundle.js:726161:49 commitPassiveUnmountEffects_begin@http://localhost:3001/static/js/bundle.js:726069:63 commitPassiveUnmountEffects@http://localhost:3001/static/js/bundle.js:726054:3 flushPassiveEffectsImpl@http://localhost:3001/static/js/bundle.js:728151:30 flushPassiveEffects@http://localhost:3001/static/js/bundle.js:728097:14 commitRootImpl@http://localhost:3001/static/js/bundle.js:728048:5 commitRoot@http://localhost:3001/static/js/bundle.js:727795:19 performSyncWorkOnRoot@http://localhost:3001/static/js/bundle.js:727230:13 flushSyncCallbacks@http://localhost:3001/static/js/bundle.js:713160:22 ./node_modules/react-dom/cjs/react-dom.development.js/ensureRootIsScheduled/<@http://localhost:3001/static/js/bundle.js:726764:13

Any help will be appreciated ! Thank you

Jiayi

hl662 commented 1 month ago

When you mean switching from the page that holds the iTwin viewer to a different page, do you explicitly close the tab? Or just move to a different tab?

lijiayi0921 commented 1 month ago

When you mean switching from the page that holds the iTwin viewer to a different page, do you explicitly close the tab? Or just move to a different tab?

I have an application where iTwin model viewer is one of the many pages. The error appears when I go to another page of the same application.

The same browser Tab is still opend.

lijiayi0921 commented 1 month ago

Just updated Chrome error message (along with the existing FF error msg)

hl662 commented 1 month ago

I see - So the page that contains the iTwin viewer will shutdown the IModelApp that holds the viewport context every time it's unmounted. We want to avoid doing so, the IModelApp should only be started up once per session, and likewise, torndown once, when the whole session of the tab that contains the Viewer ends (either through refreshing the browser page, or closing the browser tab).

In this example, an event handler beforeunload is registered, that will shutdown IModelApp only when the browser page is about to be unloaded, and not when the react component housing the Viewer is unmounted.

lijiayi0921 commented 1 month ago

In my SPA it is technically possible - and users do - close the imodel, and open another one. Keeping the same view context would it be a good solution?

Is it enough not to close the IModelApp?

thanks

On Thu, Jul 11, 2024, 19:54 Nam Le @.***> wrote:

I see - So the page that contains the iTwin viewer will shutdown the IModelApp that holds the viewport context every time it's unmounted. We want to avoid doing so, the IModelApp should only be started up once per session, and likewise, torndown once, when the whole session of the tab that contains the Viewer ends (either through refreshing the browser page, or closing the browser tab).

In this example https://github.com/iTwin/viewer/blob/0359ac61df1dab0c330b337ca77f1a6e87ac4fd3/packages/modules/web-viewer-react/src/components/Viewer.tsx#L19, an event handler beforeunload https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event is registered, that will shutdown IModelApp only when the browser page is about to be unloaded, and not when the react component housing the Viewer is unmounted.

— Reply to this email directly, view it on GitHub https://github.com/iTwin/itwinjs-core/issues/6961#issuecomment-2223540705, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACP3IWZ5I7JZR6BAP34FFWLZL3BDTAVCNFSM6AAAAABKXNHUFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRTGU2DANZQGU . You are receiving this because you authored the thread.Message ID: @.***>

lijiayi0921 commented 1 month ago

Sorry you already provided an example. thank you.

On Thu, Jul 11, 2024, 20:17 Jiayi LI @.***> wrote:

In my SPA it is technically possible - and users do - close the imodel, and open another one. Keeping the same view context would it be a good solution?

Is it enough not to close the IModelApp?

thanks

On Thu, Jul 11, 2024, 19:54 Nam Le @.***> wrote:

I see - So the page that contains the iTwin viewer will shutdown the IModelApp that holds the viewport context every time it's unmounted. We want to avoid doing so, the IModelApp should only be started up once per session, and likewise, torndown once, when the whole session of the tab that contains the Viewer ends (either through refreshing the browser page, or closing the browser tab).

In this example https://github.com/iTwin/viewer/blob/0359ac61df1dab0c330b337ca77f1a6e87ac4fd3/packages/modules/web-viewer-react/src/components/Viewer.tsx#L19, an event handler beforeunload https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event is registered, that will shutdown IModelApp only when the browser page is about to be unloaded, and not when the react component housing the Viewer is unmounted.

— Reply to this email directly, view it on GitHub https://github.com/iTwin/itwinjs-core/issues/6961#issuecomment-2223540705, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACP3IWZ5I7JZR6BAP34FFWLZL3BDTAVCNFSM6AAAAABKXNHUFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRTGU2DANZQGU . You are receiving this because you authored the thread.Message ID: @.***>