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

Error on undo: 'LayerManager' object has no attribute 'active' #862

Closed
arcusmaximus opened this issue Jun 22, 2024 · 5 comments
Closed

Error on undo: 'LayerManager' object has no attribute 'active' #862

arcusmaximus opened this issue Jun 22, 2024 · 5 comments

Comments

@arcusmaximus
Copy link

arcusmaximus commented Jun 22, 2024

This one happened when pressing Undo after accidentally flattening the entire image. No ControlNet or regions active. Sadly can't reproduce.

AttributeError
Python 3.10.7: D:\Krita\bin\krita.exe
Sun Jun 23 00:29:49 2024

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\...\AppData\Roaming\krita\pykrita\ai_diffusion\ui\generation.py in update_generate_button(self=<ai_diffusion.ui.generation.GenerationWidget object>)
  674             return
  675         has_regions = len(self.model.regions) > 0
  676         has_active_region = self.model.regions.is_linked(self.model.layers.active)
  677         is_region_only = has_regions and has_active_region and self.model.region_only
  678         self.region_mask_button.setVisible(has_regions)
has_active_region undefined
self = <ai_diffusion.ui.generation.GenerationWidget object>
self.model = <ai_diffusion.model.Model object>
self.model.regions = <ai_diffusion.region.RootRegion object>
self.model.regions.is_linked = <bound method RootRegion.is_linked of <ai_diffusion.region.RootRegion object>>
self.model.layers = <ai_diffusion.layer.LayerManager object>
self.model.layers.active undefined
AttributeError: 'LayerManager' object has no attribute 'active'
    __cause__ = None
    __class__ = <class 'AttributeError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of AttributeError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of AttributeError object>
    __doc__ = 'Attribute not found.'
    __eq__ = <method-wrapper '__eq__' of AttributeError object>
    __format__ = <built-in method __format__ of AttributeError object>
    __ge__ = <method-wrapper '__ge__' of AttributeError object>
    __getattribute__ = <method-wrapper '__getattribute__' of AttributeError object>
    __gt__ = <method-wrapper '__gt__' of AttributeError object>
    __hash__ = <method-wrapper '__hash__' of AttributeError object>
    __init__ = <method-wrapper '__init__' of AttributeError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of AttributeError object>
    __lt__ = <method-wrapper '__lt__' of AttributeError object>
    __ne__ = <method-wrapper '__ne__' of AttributeError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of AttributeError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of AttributeError object>
    __repr__ = <method-wrapper '__repr__' of AttributeError object>
    __setattr__ = <method-wrapper '__setattr__' of AttributeError object>
    __setstate__ = <built-in method __setstate__ of AttributeError object>
    __sizeof__ = <built-in method __sizeof__ of AttributeError object>
    __str__ = <method-wrapper '__str__' of AttributeError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ("'LayerManager' object has no attribute 'active'",)
    name = 'active'
    obj = <ai_diffusion.layer.LayerManager object>
    with_traceback = <built-in method with_traceback of AttributeError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\...\AppData\Roaming\krita\pykrita\ai_diffusion\ui\generation.py", line 676, in update_generate_button
    has_active_region = self.model.regions.is_linked(self.model.layers.active)
AttributeError: 'LayerManager' object has no attribute 'active'
@GeminiSquishGames
Copy link

GeminiSquishGames commented Jul 6, 2024

I've been having a lot of trouble with it saying "' has no attribute 'Active'" since I updated it recently. I can do maybe 3 or 4 operations and get a few minutes of work done but then I try to bake the generation into the layer with the check mark and nothing happens, then it'll complain about that layer not having the active attribute. I can't figure out how to reproduce but to keep working and it just seems to happen randomly. IT doesn't go away unless I restart Krita, but often times Krita will just get tired of me trying to figure out what causes it and it crashes on me. Also, getting this Script Error:

ZeroDivisionError
Python 3.10.7: D:\Graphics\Krita (x64)\bin\krita.exe
Sat Jul  6 00:00:08 2024

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\live.py in update_region(self=<ai_diffusion.ui.live.LiveWidget object>)
  219         max_lines = 1 if has_regions else 2
  220         self.region_widget.setVisible(has_regions)
  221         self.region_widget.region = self.model.regions.region_for_active_layer
  222         self.prompt_widget.header_style = PromptHeader.icon if has_regions else PromptHeader.none
  223         self.region_widget.max_lines = max_lines
self = <ai_diffusion.ui.live.LiveWidget object>
self.region_widget = <ai_diffusion.ui.region.ActiveRegionWidget object>
self.region_widget.region = <ai_diffusion.region.Region object>
self.model = <ai_diffusion.model.Model object>
self.model.regions = <ai_diffusion.region.RootRegion object>
self.model.regions.region_for_active_layer = <ai_diffusion.region.Region object>

 C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py in region(self=<ai_diffusion.ui.region.ActiveRegionWidget object>, region=<ai_diffusion.region.Region object>)
  187         if region != self._region:
  188             self._region = region
  189             self._setup_bindings(region)
  190 
  191     def _setup_bindings(self, region: RootRegion | Region | None):
self = <ai_diffusion.ui.region.ActiveRegionWidget object>
self._setup_bindings = <bound method ActiveRegionWidget._setup_bindings...i_diffusion.ui.region.ActiveRegionWidget object>>
region = <ai_diffusion.region.Region object>

 C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py in _setup_bindings(self=<ai_diffusion.ui.region.ActiveRegionWidget object>, region=<ai_diffusion.region.Region object>)
  214         ]
  215         self._update_header()
  216         self._update_links()
  217         self.positive.move_cursor_to_end()
  218         self.negative.setVisible(is_root_region and settings.show_negative_prompt)
self = <ai_diffusion.ui.region.ActiveRegionWidget object>
self._update_links = <bound method ActiveRegionWidget._update_links o...i_diffusion.ui.region.ActiveRegionWidget object>>

 C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py in _update_links(self=<ai_diffusion.ui.region.ActiveRegionWidget object>)
  275             self._link_button.setEnabled(link_enabled)
  276             self._link_button.setToolTip(desc)
  277             self._header_icon.set_region(self._region)
  278 
  279     def _update_actions(self):
self = <ai_diffusion.ui.region.ActiveRegionWidget object>
self._header_icon = <ai_diffusion.ui.region.RegionThumbnailWidget object>
self._header_icon.set_region = <bound method RegionThumbnailWidget.set_region o...iffusion.ui.region.RegionThumbnailWidget object>>
self._region = <ai_diffusion.region.Region object>

 C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py in set_region(self=<ai_diffusion.ui.region.RegionThumbnailWidget object>, region=<ai_diffusion.region.Region object>)
  439                 parent_bounds = layer.parent_layer.bounds if layer.parent_layer else layer.bounds
  440                 layer_bounds = layer.bounds.relative_to(parent_bounds)
  441                 scale = icon_size / parent_bounds.height
  442                 canvas_extent = parent_bounds.extent * scale
  443                 thumb_bounds = Bounds.scale(layer_bounds, scale)
scale undefined
icon_size = 28
parent_bounds = Bounds(x=0, y=0, width=0, height=0)
parent_bounds.height = 0
ZeroDivisionError: division by zero
    __cause__ = None
    __class__ = <class 'ZeroDivisionError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of ZeroDivisionError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of ZeroDivisionError object>
    __doc__ = 'Second argument to a division or modulo operation was zero.'
    __eq__ = <method-wrapper '__eq__' of ZeroDivisionError object>
    __format__ = <built-in method __format__ of ZeroDivisionError object>
    __ge__ = <method-wrapper '__ge__' of ZeroDivisionError object>
    __getattribute__ = <method-wrapper '__getattribute__' of ZeroDivisionError object>
    __gt__ = <method-wrapper '__gt__' of ZeroDivisionError object>
    __hash__ = <method-wrapper '__hash__' of ZeroDivisionError object>
    __init__ = <method-wrapper '__init__' of ZeroDivisionError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of ZeroDivisionError object>
    __lt__ = <method-wrapper '__lt__' of ZeroDivisionError object>
    __ne__ = <method-wrapper '__ne__' of ZeroDivisionError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of ZeroDivisionError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of ZeroDivisionError object>
    __repr__ = <method-wrapper '__repr__' of ZeroDivisionError object>
    __setattr__ = <method-wrapper '__setattr__' of ZeroDivisionError object>
    __setstate__ = <built-in method __setstate__ of ZeroDivisionError object>
    __sizeof__ = <built-in method __sizeof__ of ZeroDivisionError object>
    __str__ = <method-wrapper '__str__' of ZeroDivisionError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('division by zero',)
    with_traceback = <built-in method with_traceback of ZeroDivisionError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\live.py", line 221, in update_region
    self.region_widget.region = self.model.regions.region_for_active_layer
  File "C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py", line 189, in region
    self._setup_bindings(region)
  File "C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py", line 216, in _setup_bindings
    self._update_links()
  File "C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py", line 277, in _update_links
    self._header_icon.set_region(self._region)
  File "C:\Users\lintp\AppData\Roaming\krita\pykrita\ai_diffusion\ui\region.py", line 441, in set_region
    scale = icon_size / parent_bounds.height
ZeroDivisionError: division by zero

Will update here if I find anything, as it's the closest open issue that seems to be related, rather than making a new one.

Edit: I notice a lot of Errors that are like ERROR:root:ERROR lora diffusion_model.input_blocks.8.1.transformer_blocks.0.attn2.to_k.weight shape '[1280, 768]' is invalid for input of size 2621440 in the console also. @arcusmaximus, are you getting any errors in comfyui's console? I'm using Stability Matrix to manage the Comfy server, that makes it easier to see server errors.

Acly added a commit that referenced this issue Jul 6, 2024
 - still not sure how it can fail exactly
@Acly
Copy link
Owner

Acly commented Jul 6, 2024

ZeroDivisionError
This may legit happen if eg. the whole document is transparent (no content). At least I was able to reproduce it that way and should be fixed.

LayerManager.active
Still haven't encountered that and no idea how it could happen. I'm adding some error handling to log the actual error, maybe it will help. I have a feeling it will still produce some kind of error though since there must be something wrong if there is no active layer.

Lora errors
This is usually the result of using a SDXL Lora with SD1.5 or vice verca.

@GeminiSquishGames
Copy link

GeminiSquishGames commented Jul 7, 2024

Lora errors This is usually the result of using a SDXL Lora with SD1.5 or vice verca.

I don't use Loras in the Styles, so this might be causing compatibility issues with the xenoxtcArtToonPortraitsAnd_vtoon model in Hyper mode. Will futz with it further, and see what I see.

LayerManager Issue:

  • When I flatten the image using Shift-Ctrl-E, it creates a root Merged layer.
  • This action turns off live mode automatically if I try to send to an active or new layer.
  • It deletes the active layer and fails to create a background layer if only one layer existed, then no layers are in the project on send to active layer, nothing happens when send to new layer, no layer is created or destroyed then.

Bugged Behavior:

Restarting live mode after this error causes Krita to lose the active layer, and the generated result is not placed.
If it's the only layer remaining, Krita fails to create a default background layer, breaking the current project.
All layer functions are disabled, and no new layers can be added.
This state persists even after saving and reloading the project, (but why would anyone save a project without layers, except to send to Krita devs if needed to figure out a no layer problem?) Simply undo to a previous state and the problem should go away.

Steps to Reproduce:

Flatten the image using Shift-Ctrl-E to create a root Merged layer.
Attempt to send to an active or new layer.
Observe the deletion of the active layer and the absence of a background layer if only one layer existed, if more than one the active layer is lost and no result layer is made.

Krita might not be handling the layer removal correctly, especially when it's not done through Krita's own layer delete function. This issue could also be triggered by using the Flatten Image function itself, not sure.

Consider adding a check to ensure a background layer is created if the active layer delete problem happens and also make sure that if it can't create the result layer, that it won't, much like the create new layer from result does, that check option just doesn't make a layer when it's bugged out.

This might prevent the project from breaking and help identify other causes where the active layer gets lost. But this is all a pretty unusual use case, I only found it by trying anything I could think of to reproduce the behavior. Maybe it helps? Hopefully whatever causes it for others can be helped either with some catches. Best for user to a;sp use the script's result to active layer/ new layer and not Flatten. I was doing flatten and merge by hand before the latest version so that probably helped find that. I won't have the issue now since I won't flatten but still, it may indicate weirdness in the script and Krita?

Sorry, this is kind of a mess. I keep having to edit it after finding new things. There was an error reporting but it was actually photoshop in background trying to call the server so unrelated... hopefully this is of some value.

@Acly
Copy link
Owner

Acly commented Jul 7, 2024

It's possible there is an issue when there is only a single layer. Apply will create a new one and remove the old one, but even though the order is such that the new layer is created first, it briefly results in no layers / no active layer.

I thought the fallback worked for that though, and I couldn't really reproduce the error. Still, best to avoid the situation by delaying deletion until after Krita had a chance to process creating the new layer.

@Acly
Copy link
Owner

Acly commented Jul 7, 2024

If you are still getting errors in 1.20.0 let me know and post check client.log for error message

@Acly Acly closed this as completed Jul 7, 2024
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

3 participants