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

Unloading images crashes widget removal #375

Open
avanwinkle opened this issue Jun 22, 2019 · 0 comments
Open

Unloading images crashes widget removal #375

avanwinkle opened this issue Jun 22, 2019 · 0 comments

Comments

@avanwinkle
Copy link
Collaborator

When using a image: load: mode_start configuration to load image assets on mode start and unload on mode end, a Widget hosting the Image will crash MC.

widgets/image.py

def prepare_for_removal(self) -> None:
  """Prepare the widget to be removed."""
  super().prepare_for_removal()
  self._image.image.anim_reset(False)

By the time prepare_for_removal() is called, the Image asset has already been unloaded from the image widget so self._image.image is None, which causes a crash:
AttributeError: 'NoneType' object has no attribute 'anim_reset'

A dirty workaround is to wrap the prepare_for_removal() with an exception catch and ignore it on AttributeError.

def prepare_for_removal(self) -> None:
  """Prepare the widget to be removed."""
  super().prepare_for_removal()
  # stop any animations
  try:
    self._image.image.anim_reset(False)
  # If the image was already unloaded from memory
  except AttributeError:
    pass
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

1 participant