Timers without a user-stored reference don't fire #180
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#180
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In an object's
__init__:mcrfpy.Timer("tick", self.tick, 1000, start=True)this timer will never fire: since the user did not store a reference to it, it's silently garbage collected.
Changing it to:
self.ticker = mcrfpy.Timer("tick", self.tick, 1000, start=True)the timer operates as expected.
This defies expectations:
mcrfpy.timersshows the timer in the second case, but omits it in the first. The timer system only stores a weak reference to the python timer object, and doesn't crash when it's garbage collected, but it forces users to maintain the object even though it has a name.Implementation Complete
Fixed the timer lifecycle so that timers without a user-stored reference continue firing.
Changes Made:
std::string namemember to store timer name in C++ objectdealloccleanup that was erasing timers fromgame->timerswhen Python wrapper was GC'dcreateTimerWrapper()helper and updatedapi_get_timers()to create new Python wrappers for orphaned C++ timersNew Lifecycle Behavior:
Timer("t", cb, 1000)with no stored refmcrfpy.timerst = Timer("t", cb, 1000)tt.stop()tonce=TruetestTimers()removes from map, Timer GC'd if no Python refTests Added:
tests/issue_180_timer_orphan_test.py- Verifies orphan timers fire and are accessibletests/issue_180_timer_stopped_test.py- Verifies stopped timer lifecycleBoth tests pass.