gniziemazity / advanced_drawing_app

Making an advanced drawing app during my live streams:
MIT License
28 stars 24 forks source link

console error when the only layer is deleted. #25

Closed bantya closed 1 month ago

bantya commented 3 months ago

A console error is thrown if an only layer is deleted.

We get an error like this:

Uncaught TypeError: Cannot read properties of undefined (reading 'shapes')
    at Viewport.drawShapes (viewport.js:116:50)
    at #handleChanges (viewport.js:182:8)
    at Viewport.<anonymous> (viewport.js:238:23)
    at Viewport.removeLayerByIndex (viewport.js:174:8)
    at LayerTools.removeLayer (layerTools.js:7:12)
    at HTMLButtonElement.onclick (index.html:51:45)
Iyusuf40 commented 3 months ago

Oops we forgot to check for this. What do we do though? prevent layer 1 from being deleted or allow it to be deleted but always check if layers count is > 1 before deleting? I think I prefer to prevent layer 1 from ever being deleted as we may refer to it as primary / root layer?. Let's see what Radu prefers and maybe other suggestions.

gniziemazity commented 1 month ago

Fixed it by only showing the remove button when more than one layer is there.