Stress test is failing: By removing a timer to a function (from inside that function?) I can immediately cause a segfault.
This commit is contained in:
parent
05d9f6a882
commit
0a8f67e391
|
@ -76,7 +76,9 @@ void GameEngine::manageTimer(std::string name, PyObject* target, int interval)
|
|||
if (target == NULL || target == Py_None) // delete
|
||||
{
|
||||
//Py_DECREF(timers[name].target);
|
||||
std::cout << "Erasing a timer" << std::endl;
|
||||
timers.erase(it);
|
||||
std::cout << "It was erased" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +88,7 @@ void GameEngine::manageTimer(std::string name, PyObject* target, int interval)
|
|||
return;
|
||||
}
|
||||
timers[name] = std::make_shared<PyTimerCallable>(target, interval, runtime.getElapsedTime().asMilliseconds());
|
||||
Py_INCREF(target);
|
||||
//Py_INCREF(target);
|
||||
}
|
||||
|
||||
void GameEngine::testTimers()
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
PyCallable::PyCallable(PyObject* _target)
|
||||
{
|
||||
target = Py_XNewRef(_target);
|
||||
if (target)
|
||||
{
|
||||
//std::cout << PyUnicode_AsUTF8(PyObject_Repr(target)) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
PyCallable::~PyCallable()
|
||||
|
@ -13,6 +17,9 @@ PyCallable::~PyCallable()
|
|||
|
||||
PyObject* PyCallable::call(PyObject* args, PyObject* kwargs)
|
||||
{
|
||||
std::cout << "Calling object with args: ";
|
||||
std::cout << PyUnicode_AsUTF8(PyObject_Repr(target)) << " <- ";
|
||||
std::cout << PyUnicode_AsUTF8(PyObject_Repr(args)) << std::endl;
|
||||
return PyObject_Call(target, args, kwargs);
|
||||
}
|
||||
|
||||
|
@ -31,6 +38,7 @@ bool PyTimerCallable::hasElapsed(int now)
|
|||
|
||||
void PyTimerCallable::call(int now)
|
||||
{
|
||||
std::cout << "PyTimerCallable called. (" << (target == NULL) << ")" << std::endl;
|
||||
PyObject* args = Py_BuildValue("(i)", now);
|
||||
PyObject* retval = PyCallable::call(args, NULL);
|
||||
if (!retval)
|
||||
|
@ -47,6 +55,7 @@ void PyTimerCallable::call(int now)
|
|||
|
||||
bool PyTimerCallable::test(int now)
|
||||
{
|
||||
std::cout << "PyTimerCallable tested. (" << (target == NULL) << ")" << interval << " " << last_ran << std::endl;
|
||||
if(hasElapsed(now))
|
||||
{
|
||||
call(now);
|
||||
|
|
|
@ -9,7 +9,7 @@ texture_hot = mcrfpy.Texture("assets/kenney_lava.png", 16, 12, 11)
|
|||
|
||||
# Test stuff
|
||||
mcrfpy.createScene("boom")
|
||||
#mcrfpy.setScene("boom")
|
||||
mcrfpy.setScene("boom")
|
||||
ui = mcrfpy.sceneUI("boom")
|
||||
box = mcrfpy.Frame(40, 60, 200, 300, fill_color=(255,128,0), outline=4.0, outline_color=(64,64,255,96))
|
||||
ui.append(box)
|
||||
|
@ -36,10 +36,90 @@ box.children.append(sprite)
|
|||
box.children.append(spritecap)
|
||||
box.click = click_sprite
|
||||
|
||||
f_a = mcrfpy.Frame(250, 60, 80, 80, fill_color=(255, 92, 92))
|
||||
f_a_txt = mcrfpy.Caption(5, 5, "0", font)
|
||||
|
||||
f_b = mcrfpy.Frame(340, 60, 80, 80, fill_color=(92, 255, 92))
|
||||
f_b_txt = mcrfpy.Caption(5, 5, "0", font)
|
||||
|
||||
f_c = mcrfpy.Frame(430, 60, 80, 80, fill_color=(92, 92, 255))
|
||||
f_c_txt = mcrfpy.Caption(5, 5, "0", font)
|
||||
|
||||
|
||||
ui.append(f_a)
|
||||
f_a.children.append(f_a_txt)
|
||||
ui.append(f_b)
|
||||
f_b.children.append(f_b_txt)
|
||||
ui.append(f_c)
|
||||
f_c.children.append(f_c_txt)
|
||||
|
||||
import sys
|
||||
def ding(*args):
|
||||
f_a_txt.text = str(sys.getrefcount(ding)) + " refs"
|
||||
f_b_txt.text = sys.getrefcount(dong)
|
||||
f_c_txt.text = sys.getrefcount(stress_test)
|
||||
|
||||
def dong(*args):
|
||||
f_a_txt.text = str(sys.getrefcount(ding)) + " refs"
|
||||
f_b_txt.text = sys.getrefcount(dong)
|
||||
f_c_txt.text = sys.getrefcount(stress_test)
|
||||
|
||||
running = False
|
||||
timers = []
|
||||
|
||||
def add_ding():
|
||||
global timers
|
||||
n = len(timers)
|
||||
mcrfpy.setTimer(f"timer{n}", ding, 100)
|
||||
print("+1 ding:", timers)
|
||||
|
||||
def add_dong():
|
||||
global timers
|
||||
n = len(timers)
|
||||
mcrfpy.setTimer(f"timer{n}", dong, 100)
|
||||
print("+1 dong:", timers)
|
||||
|
||||
def remove_random():
|
||||
global timers
|
||||
target = random.choice(timers)
|
||||
print("-1 timer:", target)
|
||||
print("remove from list")
|
||||
timers.remove(target)
|
||||
print("delTimer")
|
||||
mcrfpy.delTimer(target)
|
||||
print("done")
|
||||
|
||||
import random
|
||||
def stress_test(*args):
|
||||
global running
|
||||
global timers
|
||||
if not running:
|
||||
print("stress test initial")
|
||||
running = True
|
||||
timers.append("recurse")
|
||||
add_ding()
|
||||
add_dong()
|
||||
mcrfpy.setTimer("recurse", stress_test, 1000)
|
||||
mcrfpy.setTimer("terminate", lambda *args: mcrfpy.delTimer("recurse"), 30000)
|
||||
ding(); dong()
|
||||
else:
|
||||
#print("stress test random activity")
|
||||
#random.choice([
|
||||
# add_ding,
|
||||
# add_dong,
|
||||
# remove_random
|
||||
# ])()
|
||||
#print(timers)
|
||||
print("Segfaultin' time")
|
||||
mcrfpy.delTimer("recurse")
|
||||
|
||||
stress_test()
|
||||
|
||||
|
||||
# Loading Screen
|
||||
mcrfpy.createScene("loading")
|
||||
ui = mcrfpy.sceneUI("loading")
|
||||
mcrfpy.setScene("loading")
|
||||
#mcrfpy.setScene("loading")
|
||||
logo_texture = mcrfpy.Texture("assets/temp_logo.png", 1024, 1, 1)
|
||||
logo_sprite = mcrfpy.Sprite(50, 50, logo_texture, 0, 0.5)
|
||||
ui.append(logo_sprite)
|
||||
|
|
Loading…
Reference in New Issue