question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'forEach' of undefined

See original GitHub issue

Hello there. General Kenobi.

I created a PNG Thumbnails Batch Renderer with your awesome project and sometimes it stops just because source model file has something like ‘problems with materials’ i think… BUT. I can see the model… Idk how to organize try catch with model-viewer just with vanilla js… sorry))

Can you handle this case without type error please?

model-viewer.js:56233 Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined
    at new Sm (model-viewer.js:56233)
    at HTMLElement.[onModelLoad] (model-viewer.js:56342)
    at vc.<anonymous> (model-viewer.js:48752)
    at vc.dispatchEvent (model-viewer.js:1689)
    at vc.setupScene (model-viewer.js:44589)
    at vc.setSource (model-viewer.js:44577)
    at async HTMLElement.[updateSource] (model-viewer.js:49041)
    at async HTMLElement.[updateSource] (model-viewer.js:53334)

Screens:

image

image

From:

class Model {
    constructor(correlatedSceneGraph, onUpdate = () => { }) {
        this[_a] = [];
        const { gltf, gltfElementMap } = correlatedSceneGraph;
        gltf.materials.forEach(material => {
            this[$materials].push(new Material(onUpdate, gltf, material, gltfElementMap.get(material)));
        });
    }

source glb (14mb) (not mine) https://cloudflare-ipfs.com/ipfs/QmeqKjz7KLigLis1AJGbuu22uXdgGdNaVneFF1MiDkoaPJ

from object 6137 at hic et nunc gallery.

I’ve checked source file and don’t see any “materials” property.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
elalishcommented, May 24, 2021

Since toBlob() returns a promise, I believe you can catch errors this way: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch

1reaction
elalishcommented, May 24, 2021

This looks like a regression; we have code specifically to handle this case where the glTF only has the default material.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'forEach' of undefined - Stack Overflow
And undefined has no forEach method. To fix this, always make sure you put a semicolon at the end of your lines (or...
Read more >
TypeError: Cannot read property 'forEach' of Undefined in JS
The "Cannot read property 'forEach' of undefined" error occurs when the forEach() method is called on an undefined value. To solve the error,...
Read more >
[AskJS] Why does this simple forEach give error Cannot read ...
But the following code gives an error script.js?v=3:196 Uncaught TypeError: Cannot read property 'forEach' of undefined :
Read more >
typeerror: cannot read properties of undefined (reading 'foreach')
Your problem is that you are trying to loop though the data object which is not a array. You can only use the...
Read more >
Error: Cannot read property 'forEach' of undefined #249 - GitHub
js from the contentful-management package] . Therefore this error message doesn't have the expected pattern and isn't a JSON string. Instead the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found