HaxeFoundation / HaxeFoundation/hxcpp

Calling Gc.compact() in cppia collects the current CppiaClosure/ScriptCallable?

Open
#1,196 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
330
Forks
227
Avg merge
2d 16h
Merged PRs (30d)
18

Description

I am not even sure if the title correctly describes the issue. But it seems to be the case for what I am seeing.

Looking at the stack trace below it seems like the `function` variable magically becomes null, while it was still usable 2 lines above (`function->runFunctionClosure(ctx);`)

Image

What I notice is that there is a `cpp.vm.Gc.compact()` call inside the cppia function. Removing such call seems to fix the problem.

The setup is a bit complex to be isolated. So for now I am going to first describe the setup with text and see if there any insights and I hope it is some obvious gc usage issue. The following logic all happens in the same non-haxe thread:

1. Haxe is used as a library in a c++ project and it is initialized with:
```
hxcpp_set_top_of_stack();
const char *err = hxRunLibrary();
```
1. cppia bytecode is loaded and stored in a Haxe static variable
```
module = cpp.cppia.Module.fromData(bytes);
module.boot();
```
1. a class defined in cppia is initialized (`Type.createInstance(module.resolveClass(name))`) and a instance method is invoked via `Reflect.callMethod`
1. in such instance method `cpp.vm.Gc.compact()` is called
1. the crash in the screenshot happens, after the cppia method returns

**Info:**
macos: 15 (arm64)
haxe: 4.3.6
hxcpp: git (96875093ec43e48dc2e1da95b8730e0c122ae017)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.