Skip to content

TypeError: Cannot read properties of undefined (reading 'fileName') #227

@chiaminghong

Description

@chiaminghong

I am following the hashlip youtube video - Code generate art Update Part 1.
https://www.youtube.com/watch?v=Ksb3JIomuqM&list=PLvfQp12V0hS3AVImYdMNfkdvRtZEe7xqY&index=5

Dont really understand why I Keep getting the error below when fileName existed.
Sometimes, the result returns more than 1 but it got stuck after another try.

PS D:\PROJECTS\test> node .\index.js 3
[]
created 91390203887582
red big_sr.png
D:\PROJECTS\test\index.js:54
${_layer.location}${_layer.selectedElement.fileName}
^
TypeError: Cannot read properties of undefined (reading 'fileName')
at D:\PROJECTS\test\index.js:54:57
at new Promise ()
at loadLayerImg (D:\PROJECTS\test\index.js:51:12)
at D:\PROJECTS\test\index.js:117:37
at Array.forEach ()
at startCreating (D:\PROJECTS\test\index.js:116:21)
at Object. (D:\PROJECTS\test\index.js:140:1)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)

Here are my codes:

const startCreating = async () => {
    writeMetaData("");
    let editionCount = 1;
 
    while(editionCount <= editionSize) {
        let newDna = createDna(layers.length * 2 - 1);
        console.log(dnaList);
        if (isDnaUnique(dnaList, newDna)) {
            console.log(`created ${newDna}`);
            let results = constructLayerToDna(newDna, layers);
            let loadedElements = []; //promise array
           
            results.forEach ((layer) => {
                loadedElements.push(loadLayerImg(layer)); 
            })

         await Promise.all(loadedElements).then((elementArray) => {
                elementArray.forEach((element) => {
                    drawElement(element);
                });

                signImage(`${editionCount}`);
                saveImage(editionCount);
                addMetadata(newDna, editionCount);
                console.log(`Created edition: ${editionCount} with DNA: ${newDna}`);
            });

            dnaList.push(newDna);
            editionCount++;
        } else {
            console.log("DNA Exists!!");
        }
    }
    writeMetaData(JSON.stringify(metadataList));
};

is it something wrong with the while loop and layer images??

images of my layers
image

would appreciate some explanation if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions