diff --git a/Source/Engine/Engine/NativeInterop.Unmanaged.cs b/Source/Engine/Engine/NativeInterop.Unmanaged.cs index 62fd95117..852dcb52c 100644 --- a/Source/Engine/Engine/NativeInterop.Unmanaged.cs +++ b/Source/Engine/Engine/NativeInterop.Unmanaged.cs @@ -319,14 +319,15 @@ namespace FlaxEngine.Interop var arr = (NativeMethodDefinitions*)NativeAlloc(methods.Count, Unsafe.SizeOf()); for (int i = 0; i < methods.Count; i++) { + var method = methods[i]; IntPtr ptr = IntPtr.Add(new IntPtr(arr), Unsafe.SizeOf() * i); var classMethod = new NativeMethodDefinitions { - name = NativeAllocStringAnsi(methods[i].Name), - numParameters = methods[i].GetParameters().Length, - methodAttributes = (uint)methods[i].Attributes, + name = NativeAllocStringAnsi(method.Name), + numParameters = method.GetParameters().Length, + methodAttributes = (uint)method.Attributes, }; - classMethod.typeHandle = GetMethodGCHandle(methods[i]); + classMethod.typeHandle = GetMethodGCHandle(method); Unsafe.Write(ptr.ToPointer(), classMethod); } *classMethods = arr; @@ -377,14 +378,15 @@ namespace FlaxEngine.Interop var arr = (NativePropertyDefinitions*)NativeAlloc(properties.Length, Unsafe.SizeOf()); for (int i = 0; i < properties.Length; i++) { + var property = properties[i]; IntPtr ptr = IntPtr.Add(new IntPtr(arr), Unsafe.SizeOf() * i); - var getterMethod = properties[i].GetGetMethod(true); - var setterMethod = properties[i].GetSetMethod(true); + var getterMethod = property.GetGetMethod(true); + var setterMethod = property.GetSetMethod(true); var classProperty = new NativePropertyDefinitions { - name = NativeAllocStringAnsi(properties[i].Name), + name = NativeAllocStringAnsi(property.Name), }; if (getterMethod != null) { diff --git a/Source/Engine/Scripting/Runtime/DotNet.cpp b/Source/Engine/Scripting/Runtime/DotNet.cpp index 26b011855..c2155a148 100644 --- a/Source/Engine/Scripting/Runtime/DotNet.cpp +++ b/Source/Engine/Scripting/Runtime/DotNet.cpp @@ -1000,11 +1000,12 @@ const Array& MClass::GetMethods() const int methodsCount; static void* GetClassMethodsPtr = GetStaticMethodPointer(TEXT("GetClassMethods")); CallStaticMethod(GetClassMethodsPtr, _handle, &methods, &methodsCount); + _methods.Resize(methodsCount); for (int32 i = 0; i < methodsCount; i++) { NativeMethodDefinitions& definition = methods[i]; MMethod* method = New(const_cast(this), StringAnsi(definition.name), definition.handle, definition.numParameters, definition.methodAttributes); - _methods.Add(method); + _methods[i] = method; MCore::GC::FreeMemory((void*)definition.name); } MCore::GC::FreeMemory(methods); @@ -1036,11 +1037,12 @@ const Array& MClass::GetFields() const int numFields; static void* GetClassFieldsPtr = GetStaticMethodPointer(TEXT("GetClassFields")); CallStaticMethod(GetClassFieldsPtr, _handle, &fields, &numFields); + _fields.Resize(numFields); for (int32 i = 0; i < numFields; i++) { NativeFieldDefinitions& definition = fields[i]; MField* field = New(const_cast(this), definition.fieldHandle, definition.name, definition.fieldType, definition.fieldOffset, definition.fieldAttributes); - _fields.Add(field); + _fields[i] = field; MCore::GC::FreeMemory((void*)definition.name); } MCore::GC::FreeMemory(fields); @@ -1083,11 +1085,12 @@ const Array& MClass::GetProperties() const int numProperties; static void* GetClassPropertiesPtr = GetStaticMethodPointer(TEXT("GetClassProperties")); CallStaticMethod(GetClassPropertiesPtr, _handle, &foundProperties, &numProperties); + _properties.Resize(numProperties); for (int i = 0; i < numProperties; i++) { const NativePropertyDefinitions& definition = foundProperties[i]; MProperty* property = New(const_cast(this), definition.name, definition.getterHandle, definition.setterHandle, definition.getterAttributes, definition.setterAttributes); - _properties.Add(property); + _properties[i] = property; MCore::GC::FreeMemory((void*)definition.name); } MCore::GC::FreeMemory(foundProperties); @@ -1108,10 +1111,11 @@ const Array& MClass::GetInterfaces() const int numInterfaces; static void* GetClassInterfacesPtr = GetStaticMethodPointer(TEXT("GetClassInterfaces")); CallStaticMethod(GetClassInterfacesPtr, _handle, &foundInterfaceTypes, &numInterfaces); + _interfaces.Resize(numInterfaces); for (int32 i = 0; i < numInterfaces; i++) { MClass* interfaceClass = GetOrCreateClass(foundInterfaceTypes[i]); - _interfaces.Add(interfaceClass); + _interfaces[i] = interfaceClass; } MCore::GC::FreeMemory(foundInterfaceTypes); @@ -1504,7 +1508,7 @@ MProperty::MProperty(MClass* parentClass, const char* name, void* getterHandle, { _hasGetMethod = getterHandle != nullptr; if (_hasGetMethod) - _getMethod = New(parentClass, StringAnsi("get_" + _name), getterHandle, 1, getterAttributes); + _getMethod = New(parentClass, StringAnsi("get_" + _name), getterHandle, 0, getterAttributes); else _getMethod = nullptr; _hasSetMethod = setterHandle != nullptr;