Skip to content
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

Intermittent crashes if HXCPP_GC_MOVING is enabled. #1451

Open
davidmaletz opened this issue Mar 19, 2023 · 1 comment
Open

Intermittent crashes if HXCPP_GC_MOVING is enabled. #1451

davidmaletz opened this issue Mar 19, 2023 · 1 comment

Comments

@davidmaletz
Copy link

Describe the bug
If you enable the HXCPP_GC_MOVING flag (which makes the garbage collector more efficient/able to decrease fragmentation), then you'll get intermittent crashes due to kinc storing currentPipeline to the address of a potentially moved object (and perhaps other similar safety issues).

To Reproduce
Unfortunately, this is tough to reproduce - as even if you enable the HXCPP_GC_MOVING flag, this crash will only occur if the garbage collector runs and moves the bound shader object at the wrong time. However, it's pretty easy to see how this happens from PipelineState.hx:

Binding a shader calls:
@:functionCode("kinc_g4_set_pipeline(&pipeline);")

And pipeline is a struct in the actual PipelineState object, which is a haxe object that can be moved by the garbage collector:
@:headerClassCode("kinc_g4_pipeline_t pipeline;")

I've identified many other cases of passing a reference of a struct in an object that can be moved which could be unsafe, but I've only seen a crash with pipelines because currentPipeline can hold a pointer to pipeline for a while.

Expected behavior
currentPipleline must be aware that the object address can change, or should be passed a pointer to a kinc_g4_pipeline_t that was created via malloc/new and therefore never touched by the garbage collector. Alternatively, the garbage collector could be paused during the renderFrame call (I think enterGCFreeZone/exitGCFreeZone can do that - although those are for multithreading).

Execution Environment:
This is on windows, but theoretically any kinc-hxcpp target should have this same problem.

@RobDangerous
Copy link
Member

Kinc has nothing to do with hxcpp. Moving this to Kha.

@RobDangerous RobDangerous transferred this issue from Kode/Kinc Mar 19, 2023
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

2 participants