Skip to content

Commit

Permalink
Merge pull request #136 from labuzm/fix_wrapper
Browse files Browse the repository at this point in the history
fix freeing of python wrapper
  • Loading branch information
labuzm committed Feb 11, 2022
2 parents f55fcf7 + 3767679 commit 54d634d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/kaa/nodes.pxi
Expand Up @@ -67,17 +67,11 @@ cdef cppclass CPyNodeWrapper(CForeignNodeWrapper):

py_wrapper._reset()
result.unwrap_result()
this._release_wrapper()

__dealloc__() nogil:
if this.added_to_parent:
with gil:
this._release_wrapper()

void _release_wrapper() with gil:
Py_XDECREF(this.py_wrapper)
this.py_wrapper = NULL
this.added_to_parent = False
Py_XDECREF(this.py_wrapper)


@cython.freelist(NODE_FREELIST_SIZE)
Expand Down
23 changes: 23 additions & 0 deletions tests/test_tree.py
@@ -0,0 +1,23 @@
import pytest

from kaa.nodes import Node

from tests.utils import TestScene


class ChildNode(Node):
def on_attach(self):
assert self.parent

def on_detach(self):
# parent is already deleted
assert not self.parent


@pytest.mark.usefixtures('test_engine')
def test_on_callbacks():
parent = Node()
parent.add_child(ChildNode())
scene = TestScene(lambda scene, dt: parent.delete())
scene.root.add_child(parent)
scene.run_on_engine(1)
19 changes: 19 additions & 0 deletions tests/utils.py
@@ -0,0 +1,19 @@
from kaa.engine import Scene


class TestScene(Scene):
def __init__(self, update_function):
self._frames = None
self._test_update_function = update_function

def update(self, dt):
if self._frames == 0:
self.engine.quit()
return

self._test_update_function(self, dt)
self._frames -= 1

def run_on_engine(self, frames):
self._frames = frames
self.engine.run(self)

0 comments on commit 54d634d

Please sign in to comment.