diff --git a/python/caca/canvas.py b/python/caca/canvas.py index 7fc0a74..046a1c3 100644 --- a/python/caca/canvas.py +++ b/python/caca/canvas.py @@ -38,7 +38,7 @@ class _Canvas(object): return "" % (self.get_width(), self.get_height()) def __del__(self): - if self._cv > 0: + if self._cv > 0 and _lib is not None: self._free() def _free(self): @@ -47,10 +47,7 @@ class _Canvas(object): _lib.caca_free_canvas.argtypes = [_Canvas] _lib.caca_free_canvas.restype = ctypes.c_int - if self is not None: - return _lib.caca_free_canvas(self) - - return None + return _lib.caca_free_canvas(self) class Canvas(_Canvas): """ Canvas object, methods are libcaca functions with canvas_t as diff --git a/python/caca/display.py b/python/caca/display.py index 93e028b..7cf4d71 100644 --- a/python/caca/display.py +++ b/python/caca/display.py @@ -32,7 +32,7 @@ class _Display(object): return "" def __del__(self): - if self._dp > 0: + if self._dp > 0 and _lib is not None: self._free() def _free(self): @@ -43,6 +43,7 @@ class _Display(object): return _lib.caca_free_display(self) + class Display(_Display): """ Display objects, methods are libcaca functions with display_t as first parameter.