Skip to content

Pointers and References

ZSolarDev edited this page Nov 16, 2026 · 1 revision

You need to be VERY careful about this when using Hx4Diva: pointers and references.

Due to the fact that haxe usually handles objects automatically, and due to the fact that there's no pointer system at a language level by default, I had to use hxcpp's methods of exposing interactions with pointers and references. And it does work, but I've discovered that it's extremely easy to accidentally copy and/or dereference an object wrapped in Reference<T> or Star<T>.

This really is all it takes:

// Let's say ctx.foo is of type cpp.Reference<Foo>.
var foo:Foo = ctx.foo;

This code means foo would no longer be a reference to its original object. And it really is an easy fix:

var foo = ctx.foo;

Just let the compiler type it for you. Alternatively:

var foo:Reference<Foo> = ctx.foo;

Type it yourself. I personally prefer the former solution, because I don't have to try as hard to make it a habit to think about what's referencing what.

Keep track of what's a Star<T> and what's a Reference<T>. They're able to be interacted with/have their fields accessed like normal haxe objects, so it's easy to forget that these aren't normal haxe-managed objects. If you mix them up, it usually fails to compile.

Code with that caution in mind.

Clone this wiki locally