Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested types gen fixes #2590

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,12 +1637,21 @@ private static void GenerateCSharpStructure(BuildData buildData, StringBuilder c
}
else if (fieldInfo.Type.Type == "Array" || fieldInfo.Type.Type == "Span" || fieldInfo.Type.Type == "DataContainer" || fieldInfo.Type.Type == "BytesContainer")
{
string originalElementType = originalType.Substring(0, originalType.Length - 2);
string originalElementType = originalType[0..^2];

if (internalType)
{
// Marshal blittable array elements back to original non-blittable elements
string originalElementTypeMarshaller = originalElementType + "Marshaller";
string internalElementType = $"{originalElementTypeMarshaller}.{originalElementType}Internal";
//[Nori_SC note]
//Find all characters after last . as a example if the c++ type is Class.Struct it will generate a invalid c# code
//with will look like this <Class>.<Struct>Marshaller.<Class>.<Struct>Internal
//valid code looks like this <Class>.<Struct>Marshaller.<Struct>Internal

var startindex = originalElementType.LastIndexOf('.') + 1;

string internalElementType = $"{originalElementTypeMarshaller}.{originalElementType[startindex..]}Internal";

toManagedContent.AppendLine($"unmanaged.{fieldInfo.Name} != IntPtr.Zero ? NativeInterop.ConvertArray((Unsafe.As<ManagedArray>(ManagedHandle.FromIntPtr(unmanaged.{fieldInfo.Name}).Target)).ToSpan<{internalElementType}>(), {originalElementTypeMarshaller}.ToManaged) : null;");
toNativeContent.AppendLine($"managed.{fieldInfo.Name}?.Length > 0 ? ManagedHandle.ToIntPtr(ManagedArray.WrapNewArray(NativeInterop.ConvertArray(managed.{fieldInfo.Name}, {originalElementTypeMarshaller}.ToNative)), GCHandleType.Weak) : IntPtr.Zero;");
freeContents.AppendLine($"if (unmanaged.{fieldInfo.Name} != IntPtr.Zero) {{ ManagedHandle handle = ManagedHandle.FromIntPtr(unmanaged.{fieldInfo.Name}); Span<{internalElementType}> values = (Unsafe.As<ManagedArray>(handle.Target)).ToSpan<{internalElementType}>(); foreach (var value in values) {{ {originalElementTypeMarshaller}.Free(value); }} (Unsafe.As<ManagedArray>(handle.Target)).Free(); handle.Free(); }}");
Expand Down
5 changes: 5 additions & 0 deletions Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,11 @@ private static void GenerateCppEnum(BuildData buildData, StringBuilder contents,
var enumTypeNameManaged = enumInfo.FullNameManaged;
var enumTypeNameInternal = enumInfo.FullNameNativeInternal;

//patch generating bug
//if code contains Class::Struct::Enum it will generate Class::Struct_Enum but class don't contains set type
var custoff1 = enumTypeNameInternal.LastIndexOf(':') + 1;
enumTypeNameInternal = enumTypeNameInternal[custoff1..];

contents.AppendLine();
contents.AppendFormat("class {0}Internal", enumTypeNameInternal).AppendLine();
contents.Append('{').AppendLine();
Expand Down
Loading