diff --git a/include/app/app.h b/include/app/app.h index 5d9e436..c8fe817 100644 --- a/include/app/app.h +++ b/include/app/app.h @@ -27,7 +27,6 @@ struct Element { virtual Vec2 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); } } diff --git a/include/binding/ruby.h b/include/binding/ruby.h index fa364ca..bb71a0b 100644 --- a/include/binding/ruby.h +++ b/include/binding/ruby.h @@ -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;