mpf-mc icon indicating copy to clipboard operation
mpf-mc copied to clipboard

Unloading images crashes widget removal

Open avanwinkle opened this issue 5 years ago • 0 comments

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

avanwinkle avatar Jun 22 '19 21:06 avanwinkle