From 208010af198c1f40c4c538a508891afc86eb00df Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 19 Oct 2025 18:52:33 +0100 Subject: [PATCH 1/2] Fix cpp.Pointer.ofArray with empty array array[0] had a side effect of extending an empty array to size 1. Now, the pointer is retrieved directly without the [] access which prevents the array being extended. --- include/cpp/Pointer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cpp/Pointer.h b/include/cpp/Pointer.h index 48aaa50f7..582947cba 100644 --- a/include/cpp/Pointer.h +++ b/include/cpp/Pointer.h @@ -503,7 +503,7 @@ class Pointer_obj } template - inline static AutoCast ofArray(::Array array) { return AutoCast(&array[0]); } + inline static AutoCast ofArray(::Array array) { return AutoCast(array->Pointer()); } inline static AutoCast ofArray(Dynamic inVal) { if (inVal==null() || !inVal->__IsArray()) From e61e91905b29692a065f4dc82e023857c2e9a6fe Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Tue, 13 Jan 2026 21:21:02 +0000 Subject: [PATCH 2/2] [tests] Check cpp.Pointer.ofArray with empty array --- test/native/tests/TestPtr.hx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/native/tests/TestPtr.hx b/test/native/tests/TestPtr.hx index cbbfa8905..dfd58784d 100644 --- a/test/native/tests/TestPtr.hx +++ b/test/native/tests/TestPtr.hx @@ -213,6 +213,17 @@ class TestPtr extends Test static function notProcAddress(module:String, func:String) return null; + // See: https://github.com/HaxeFoundation/hxcpp/issues/1028 + public function testOfEmptyArray() { + var empty:Array = []; + cpp.Pointer.ofArray( empty ); + Assert.equals( 0, empty.length ); + + var emptyInt:Array = []; + cpp.Pointer.ofArray( emptyInt ); + Assert.equals( 0, emptyInt.length ); + } + public function testArrayAccess() { var array = [ 0.0, 1.1, 2.2, 3.3 ]; var ptr = cpp.Pointer.arrayElem(array, 0);