Orama-Interactive / Pixelorama

Unleash your creativity with Pixelorama, a powerful and accessible open-source pixel art multitool. Whether you want to create sprites, tiles, animations, or just express yourself in the language of pixel art, this software will realize your pixel-perfect dreams with a vast toolbox of features. Available on Windows, Linux, macOS and the Web!
https://orama-interactive.itch.io/pixelorama
MIT License
7.24k stars 387 forks source link

Fix Orama-Interactive#958 (reset custom brush when switch another tool) #1078

Closed alikin12 closed 3 months ago

alikin12 commented 3 months ago

This should fix issue #958 (reset custom brush when switch another tool) by removing the childs safely from BrushPopup when project data is cleared.

OverloadedOrama commented 3 months ago

Hello, thank you for the contribution! I'm not sure I understand what this change accomplishes, or how it's related to issue #958. I am trying to switch between projects with and without your change and I do not notice anything different. Can you explain how this fixes an issue?

alikin12 commented 3 months ago

Hello. First of all I want to thank you for your great work and the effort you and all other people who are involved in this project put into pixelorama. It's a very nice tool.

Regarding the issue and my fix I try to explain how to reproduce the issue and how the change fixes it:

Reproducing issue:

  1. Create new brush
  2. Save the project
  3. Open the project a second time (or close the project and reopen it. Important is that the project is reloaded)
  4. In the reloaded project: Select pencil tool and set brush to the new created brush. The brush should now be correctly selected
  5. Change to any other tool
  6. Change back to pencil tool. Now the self created brush is no more selected but the default Pixel brush

All this happens only when project was saved and reloaded. It does not happen without the reloading step.

Fix: The issue appears because when a project is loaded, the brushes are added in the open_pxo_file method by add_project_brush. After that the change_project method is called which should clear all brushed and repopulate it again with the project ones. Without the fix the old brushes are not cleared directly (I think because queue_free() takes effect only on the next frame) and when the new brushes are added, the index which is set by get_index() is set to the wrong value as the old brushes still exist and the index has now an offset of the old brushs count. When switching the tool from another tool back to pencil, the brush with the wrong (not existing) index is tried to selected. As the child with this index does not exist, it fails and the default brush is selected.

Hope that helps :)