ThatOpen / engine_components

MIT License
350 stars 134 forks source link

After fragments.dipose(), the FragmentHighlighter is not reseted #170

Closed agonzalezesteve closed 12 months ago

agonzalezesteve commented 1 year ago

Describe the bug 📝

Fragments data from different tools is not reseted after fragments.dispose().

Similar to #134.

Reproduction ▶️

No response

Steps to reproduce 🔢

Every time that I load an IFC file, I delete the previous one using this method:

    async dispose() {
        const fragments = await this.components.tools.get(OBC.FragmentManager);
        void fragments.dispose();
        const disposer = await this.components.tools.get(OBC.Disposer);
        for (const mesh of this.components.meshes) {
            disposer.destroy(mesh);
        }
        this.components.meshes.length = 0;
    }

Once I load the new IFC, I run a components.init() in order to update all the current tools.

System Info 💻

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
    Memory: 6.45 GB / 15.87 GB
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 119.0.6045.124
    Edge: Spartan (44.19041.3570.0), Chromium (119.0.2151.58)
    Internet Explorer: 11.0.19041.3570

Used Package Manager 📦

npm

Error Trace/Logs 📃

I get the following error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'blocks')
    at FragmentHighlighter.clearOutlines (webpack-internal:///(:3000/app-pages-browser)/./node_modules/openbim-components/fragments/FragmentHighlighter/index.js:399:46)
    at async FragmentHighlighter.clear (webpack-internal:///(:3000/app-pages-browser)/./node_modules/openbim-components/fragments/FragmentHighlighter/index.js:253:13)
    at async FragmentHighlighter.highlight (webpack-internal:///(:3000/app-pages-browser)/./node_modules/openbim-components/fragments/FragmentHighlighter/index.js:172:13)
    at async FragmentHighlighter.onMouseUp (webpack-internal:///(:3000/app-pages-browser)/./node_modules/openbim-components/fragments/FragmentHighlighter/index.js:94:13)

Validations ✅

HoyosJuan commented 1 year ago

Hey @agonzalezesteve! Just for the note, you're disposing the whole tool, not just the model. If you want to dispose the model (FragmentsGroup) then use FragmentsManager.disposeGroup(). Maybe this could help you someway!

agonzalezesteve commented 1 year ago

Hey @agonzalezesteve! Just for the note, you're disposing the whole tool, not just the model. If you want to dispose the model (FragmentsGroup) then use FragmentsManager.disposeGroup(). Maybe this could help you someway!

Ok, good to know, thanks!

HoyosJuan commented 1 year ago

I will take care of this by adding a new onFragmentsGroupDispose event in the FragmentsManager tool to clean up any information in other tools that are model-specific.

HoyosJuan commented 12 months ago

Solved in PR https://github.com/IFCjs/components/pull/197.