Skip to content

Accidental Dereferences

ZSolarDev edited this page Nov 9, 2026 · 1 revision

You need to be VERY careful about this when using Hx4Diva: dereferencing and/or copying objects.

Due to the fact that haxe usually handles memory automatically, and due to the fact that there's no pointer system by default, I had to use the one from hxcpp. And it does work, but I've discovered that it's extremely easy to accidentally copy and/or dereference an object wrapped in Reference, Pointer, RawPointer, etc.

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.

Code with that caution in mind.

Clone this wiki locally