ghostopened on Feb 24, 2023 · GitHub

I'm trying to create a block using the C API, but I keep getting a segfault. This is the code below:

mrb_value proc_test(mrb_state *mrb, mrb_value self) {
        return mrb_false_value();
}
struct RProc *p = mrb_proc_new_cfunc(mrb, proc_test);
mrb_value b = mrb_obj_value(p);
mrb_yield(mrb, b, mrb_nil_value());

The problem seems to the variable mrb_value b. I have no idea why!

Even when I use mrb_p trying to see if I'm getting the expected object value it just crashes! What's going on here?

Valgrind gives me this output in regard to the error:

Invalid read of size 8
0x12DE5A: mrb_yield.cold (vm.c:999)
0x130C45: data_manager_parse (MRB_DataManager.c:54)
0x15A42B: mrb_vm_exec (vm.c:1792)
0x162CF5: mrb_vm_run (vm.c:1282)
0x1630AD: mrb_run (vm.c:3100)
0x1630AD: mrb_funcall_with_block (vm.c:681)
0x1636E9: mrb_funcall_with_block (vm.c:637)
0x163AAD: mrb_funcall_argv (vm.c:692)
0x163AAD: mrb_funcall (vm.c:484)
0x1307C5: RunGame (CORE_Main.c:142)
0x1308FB: CORE_Main (CORE_Main.c:45)
0x12E068: main (Main.c:17)
Address 0x18 is not stack'd, malloc'd or (recently) free'd

Why is it an invalid read?? And what is mrb_yield.cold??

Can I get an example of how to create a block using the C API?

Read the original on github.com ↗