lospec / pixel-editor

An online canvas based Pixel Art creation tool for Lospec.com

Home Page:https://Lospec.com/pixel-editor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read property 'specified' of undefined (on creating new drawing)

jywarren opened this issue · comments

I'm seeing this error on trying to create a new drawing. I love lospec! Thanks for an awesome app!

image

pixel-editor.js:1 Uncaught TypeError: Cannot read property 'specified' of undefined
    at newPixel (pixel-editor.js:1)
    at pixel-editor.js:1
    at HTMLButtonElement.<anonymous> (pixel-editor.js:1)

So the line of code is:

if("Choose a palette..."!=r)palettes[r].specified||history.pushState

So I think probably line 36 of:

if (selectedPalette != 'Choose a palette...') {
//if this palette isnt the one specified in the url, then reset the url
if (!palettes[selectedPalette].specified)
history.pushState(null, null, '/pixel-editor/app');
//fill the palette with specified palette
createColorPalette(palettes[selectedPalette].colors,true);

palettes is not defined in that file, and there was an edit 27 days ago, so I wonder...

Here, in the last commit affecting that file, it seems to be a global:

f3ce09a#diff-d31f5dbff40507ec6a2607a0f70e281aR2

It is a global, from the JS console of the live app!

OK, i think i figured this out. When you first load the editor, you see this, where both dropdowns say Choose a _____...

image

But, unfortunately, when you choose a preset, it inserts that selection into the 2nd dropdown, even though that's not a valid choice:

image

Then when you press Create it tries to select a palette that doesn't exist (like Pico 8, in my screenshot).

What's happening is that when the preset is selected, it's adding the preset's palette property to the palettes dropdown. See the presets here:

"{"Gameboy Color":{"width":240,"height":203,"palette":"Gameboy Color"},"PICO-8":{"width":128,"height":128,"palette":"PICO-8"},"Commodore 64":{"width":40,"height":80,"palette":"Commodore 64"}}"

The palette options don't include these: "Endesga 32", "Zughy 32", "AAP-64", "Pear36", "Endesga 64", "Sweetie 16", "Journey", "Famicube", "Fantasy 24", "Vinik24"

I looked through recent changes to see if recent changes might have affected this, but couldn't trace where the palettes themselves are generated...

BUT:

Work-around:

Just manually select a palette that DOES exist, and you can make an icon!