Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kevinresol opened this issue Mar 3, 2025 · 1 comment

Comments

@kevinresol
Copy link

kevinresol commented Mar 3, 2025

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();
    
  2. cppia bytecode is loaded and stored in a Haxe static variable
    module = cpp.cppia.Module.fromData(bytes);
    module.boot();
    
  3. a class defined in cppia is initialized (Type.createInstance(module.resolveClass(name))) and a instance method is invoked via Reflect.callMethod
  4. in such instance method cpp.vm.Gc.compact() is called
  5. the crash in the screenshot happens, after the cppia method returns

Info:
macos: 15 (arm64)
haxe: 4.3.6
hxcpp: git (9687509)

@kevinresol kevinresol changed the title Calling Gc.compact() in cppia collects the current ScriptCallable? Calling Gc.compact() in cppia collects the current CppiaClosure/ScriptCallable? Mar 3, 2025
@kevinresol
Copy link
Author

In nightly haxe/hxcpp I actually get a Critical Error: Bad Allocation while collecting - from finalizer? when I run Gc.compact(). So this makes me curious: what is the correct usage of Gc.compact() within cppia?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant