Skip to content

Commit 58d8643

Browse files
committed
fixed horrendous __del__ method and other regressions
1 parent c37ff2e commit 58d8643

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

tdl/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def __init__(self, width, height):
767767
"""
768768
_MetaConsole.__init__(self)
769769
if not _rootinitialized:
770-
raise TDLError('Can not create Console\'s before tdl.init')
770+
raise TDLError('Can not create Console instances before a call to tdl.init')
771771
self._as_parameter_ = _lib.TCOD_console_new(width, height)
772772
self.console = self
773773
self.width = width
@@ -791,15 +791,18 @@ def __del__(self):
791791
"""
792792
If the main console is garbage collected then the window will be closed as well
793793
"""
794-
# If this is the root console the window will close when collected
795-
try:
796-
if isinstance(self._as_parameter_, ctypes.c_void_p):
797-
global _rootinitialized, _rootConsoleRef
794+
global _rootinitialized, _rootConsoleRef
795+
# check of see if the pointer is to the special root console
796+
if isinstance(self._as_parameter_, ctypes.c_void_p):
797+
# do we recognise this root console?
798+
if(_rootConsoleRef and _rootConsoleRef is self):
798799
_rootinitialized = False
799800
_rootConsoleRef = None
801+
_lib.TCOD_console_delete(self)
802+
# if not then assume the console has already been taken care of
803+
else:
804+
# this is a normal console pointer and can be safely deleted
800805
_lib.TCOD_console_delete(self)
801-
except StandardError:
802-
pass # I forget why I put this here but I'm to afraid to delete it
803806

804807
def __copy__(self):
805808
# make a new class and blit

tdl/__tcod.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ class SDL_Surface(Structure):
9898

9999
# COLOR
100100

101+
# python 2 to 3 workaround
102+
if sys.version_info[0] == 2:
103+
int_types = (int, long)
104+
else:
105+
int_types = int
106+
101107
class _Color(Structure):
102108
_fields_ = [('r', c_uint8), ('g', c_uint8), ('b', c_uint8)]
103109

@@ -107,7 +113,7 @@ def new(color):
107113
return color
108114
if isinstance(color, _Color):
109115
return color
110-
if isinstance(color, int):
116+
if isinstance(color, int_types):
111117
# format a web style color with the format 0xRRGGBB
112118
return _Color(color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff)
113119
return _Color(*color)

0 commit comments

Comments
 (0)