InvokeAI/invokeai/frontend
psychedelicious 34a09cb4ca fix(ui): fix send to canvas crash
A few weeks back, we changed how the canvas scales in response to changes in window/panel size.

This introduced a bug where if we the user hadn't already clicked the canvas tab once to initialize the stage elements, the stage's dimensions were zero, then the calculation of the stage's scale ends up zero, then something is divided by that zero and Konva dies.

This is only a problem on Chromium browsers - somehow Firefox handles it gracefully.

Now, when calculating the stage scale, never return a 0 - if it's a zero, return 1 instead. This is enough to fix the crash, but the image ends up centered on the top-left corner of the stage (the origin of the canvas).

Because the canvas elements are not initialized at this point (we haven't switched tabs yet), the stage dimensions fall back to (0,0). This means the center of the stage is also (0,0) - so the image is centered on (0,0), the top-left corner of the stage.

To fix this, we need to ensure we:
- Change to the canvas tab before actually setting the image, so the stage elements are able to initialize
- Use `flushSync` to flush DOM updates for this tab change so we actually have DOM elements to work with
- Update the stage dimensions once on first load of it (so in the effect that sets up the resize observer, we update the stage dimensions)

The result now is the expected behaviour - images sent to canvas do not crash and end up in the center of the canvas.
2023-09-15 11:05:53 +10:00
..
CLI Resolving merge conflicts for flake8 2023-08-18 15:52:04 +10:00
install isort wip 2023-09-12 13:01:58 -04:00
merge isort wip 2023-09-12 13:01:58 -04:00
training isort wip 2023-09-12 13:01:58 -04:00
web fix(ui): fix send to canvas crash 2023-09-15 11:05:53 +10:00
__init__.py Run python black 2023-07-28 09:46:44 -04:00
legacy_launch_invokeai.py isort wip 2023-09-12 13:01:58 -04:00