Fix gc issue
This commit is contained in:
+1
-4
@@ -27,7 +27,6 @@ struct Element {
|
||||
virtual Vec2<float> size(Window *window) = 0;
|
||||
|
||||
void click() {
|
||||
printf("Running click handler\n");
|
||||
on_click.call();
|
||||
}
|
||||
};
|
||||
@@ -78,8 +77,7 @@ struct EText : Element {
|
||||
|
||||
EText(Localization::Key key, uint64_t font_id, Color color, mrb_value params)
|
||||
: Element(Type::TEXT), key(key), font_id(font_id), color(color), params(params) {
|
||||
if (!mrb_nil_p(params))
|
||||
mrb_gc_protect(Ruby::mrb, params);
|
||||
mrb_gc_register(Ruby::mrb, params);
|
||||
font_pool.use(font_id);
|
||||
}
|
||||
|
||||
@@ -170,7 +168,6 @@ struct Scene {
|
||||
void update_scene(uint64_t delta_time) {
|
||||
if (!mrb_nil_p(update.proc)) {
|
||||
mrb_value dt_val = mrb_int_value(Ruby::mrb, delta_time);
|
||||
printf("running: update, dt: %lu\n", delta_time);
|
||||
update.call(1, &dt_val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,14 +54,21 @@ struct Block {
|
||||
mrb_value proc;
|
||||
|
||||
Block(mrb_value proc) : proc(proc) {
|
||||
mrb_gc_protect(mrb, proc);
|
||||
mrb_gc_register(mrb, proc);
|
||||
}
|
||||
|
||||
Block() : proc(mrb_nil_value()) {}
|
||||
|
||||
~Block() {
|
||||
if (!mrb_nil_p(proc))
|
||||
mrb_gc_unregister(mrb, proc);
|
||||
}
|
||||
|
||||
void set_proc(mrb_value new_proc) {
|
||||
if (!mrb_nil_p(proc))
|
||||
mrb_gc_unregister(mrb, proc);
|
||||
proc = new_proc;
|
||||
mrb_gc_protect(mrb, proc);
|
||||
mrb_gc_register(mrb, proc);
|
||||
}
|
||||
|
||||
Block(const Block &) = delete;
|
||||
|
||||
Reference in New Issue
Block a user