Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chiaminghong opened this issue Mar 22, 2022 · 0 comments
Open

Comments

@chiaminghong
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant