Skip to content

Commit

Permalink
pychan: Remove Icon from manager on source load failure
Browse files Browse the repository at this point in the history
When creating an `Icon` with an invalid file path, the `Icon` object
first calls its parent's `__init__()` and then trys to load the image
source.  Loading the image might end up in e.g. `fife.NotFound`, but the
parent's `__init__()` already added the new `Icon` instance to the
manager. So while the code creating the `Icon` will never see an
instance of it and can never call `hide()` to remove it, the manager
still thinks that there's an instance available.

This commit changes to code to remove the `Icon` from the manager for
any occuring exception and then re-raise the exception.
  • Loading branch information
MasterofJOKers committed Jan 26, 2017
1 parent 763a737 commit 2efebb3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion engine/python/fife/extensions/pychan/widgets/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from fife.extensions.pychan.attrs import Attr, BoolAttr
from fife.extensions.pychan.properties import ImageProperty

from common import get_manager
from widget import Widget


Expand Down Expand Up @@ -88,7 +89,11 @@ def __init__(self,

if scale is not None: self.scale = scale

self.image = image
try:
self.image = image
except Exception:
get_manager().removeWidget(self)
raise

#if the size parameter is specified set it (again) to override
#the icons size.
Expand Down

0 comments on commit 2efebb3

Please sign in to comment.