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()) 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);