_assetref setunsafe (unstable buggy)
This commit is contained in:
@@ -217,6 +217,17 @@ public:
|
|||||||
{
|
{
|
||||||
OnSet(asset);
|
OnSet(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the asset reference without binding the events.
|
||||||
|
/// This should only be used cautiously in cases where the reference needs to be held for a short time (for example in while marshalling managed types).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset">The asset.</param>
|
||||||
|
void SetUnsafe(T* asset)
|
||||||
|
{
|
||||||
|
ASSERT(_asset == nullptr || asset == nullptr);
|
||||||
|
_asset = asset;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@@ -715,8 +715,16 @@ namespace Flax.Build.Bindings
|
|||||||
// For non-pod types converting only, other API converts managed to unmanaged object in C# wrapper code)
|
// For non-pod types converting only, other API converts managed to unmanaged object in C# wrapper code)
|
||||||
if (CppNonPodTypesConvertingGeneration)
|
if (CppNonPodTypesConvertingGeneration)
|
||||||
{
|
{
|
||||||
type = "MObject*";
|
if (typeInfo.Type == "AssetReference")
|
||||||
return "(" + typeInfo.GenericArgs[0].Type + "*)ScriptingObject::ToNative({0})";
|
{
|
||||||
|
type = "MObject*";
|
||||||
|
return "(" + typeInfo.GenericArgs[0].Type + "*)ScriptingObject::ToNative({0})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
type = "MObject*";
|
||||||
|
return "(" + typeInfo.GenericArgs[0].Type + "*)ScriptingObject::ToNative({0})";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type = typeInfo.GenericArgs[0].Type + '*';
|
type = typeInfo.GenericArgs[0].Type + '*';
|
||||||
@@ -1264,7 +1272,7 @@ namespace Flax.Build.Bindings
|
|||||||
callParams += parameterInfo.Name;
|
callParams += parameterInfo.Name;
|
||||||
callParams += "Temp";
|
callParams += "Temp";
|
||||||
}
|
}
|
||||||
// Instruct for more optoimized value move operation
|
// Instruct for more optimized value move operation
|
||||||
else if (parameterInfo.Type.IsMoveRef)
|
else if (parameterInfo.Type.IsMoveRef)
|
||||||
{
|
{
|
||||||
callParams += $"MoveTemp({param})";
|
callParams += $"MoveTemp({param})";
|
||||||
@@ -1357,6 +1365,27 @@ namespace Flax.Build.Bindings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Free special native resources
|
||||||
|
bool needsCleanup = false;
|
||||||
|
for (var i = 0; i < functionInfo.Parameters.Count; i++)
|
||||||
|
{
|
||||||
|
var parameterInfo = functionInfo.Parameters[i];
|
||||||
|
if (/*CppParamsThatNeedConversion[i] ||*/ CppParamsThatNeedLocalVariable[i])
|
||||||
|
{
|
||||||
|
needsCleanup = true;
|
||||||
|
//break;
|
||||||
|
//if (parameterInfo.Type.Type == "AssetReference")
|
||||||
|
var apiType = FindApiTypeInfo(buildData, parameterInfo.Type, caller);
|
||||||
|
if (apiType != null && apiType.IsStruct && !apiType.IsPod)
|
||||||
|
contents.Append(indent).AppendFormat("FreeNative({0}Temp);", parameterInfo.Name).AppendLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsCleanup)
|
||||||
|
{
|
||||||
|
//contents.Append(indent).AppendFormat("FreeNative({0});", parameterInfo.Name, value).AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
if (!useInlinedReturn && !functionInfo.Glue.UseReferenceForResult && !functionInfo.ReturnType.IsVoid)
|
if (!useInlinedReturn && !functionInfo.Glue.UseReferenceForResult && !functionInfo.ReturnType.IsVoid)
|
||||||
{
|
{
|
||||||
contents.Append(indent).Append("return __result;").AppendLine();
|
contents.Append(indent).Append("return __result;").AppendLine();
|
||||||
@@ -2937,6 +2966,7 @@ namespace Flax.Build.Bindings
|
|||||||
header.AppendLine("namespace {");
|
header.AppendLine("namespace {");
|
||||||
header.AppendFormat("{0} ToManaged(const {1}& value);", wrapperName, fullName).AppendLine();
|
header.AppendFormat("{0} ToManaged(const {1}& value);", wrapperName, fullName).AppendLine();
|
||||||
header.AppendFormat("{1} ToNative(const {0}& value);", wrapperName, fullName).AppendLine();
|
header.AppendFormat("{1} ToNative(const {0}& value);", wrapperName, fullName).AppendLine();
|
||||||
|
header.AppendFormat("void FreeNative({0}& value);", fullName).AppendLine();
|
||||||
header.AppendLine("}");
|
header.AppendLine("}");
|
||||||
|
|
||||||
// Generate MConverter for a structure
|
// Generate MConverter for a structure
|
||||||
@@ -3038,13 +3068,30 @@ namespace Flax.Build.Bindings
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(wrapper))
|
if (fieldInfo.Type.Type == "AssetReference" && !string.IsNullOrEmpty(wrapper))
|
||||||
|
header.AppendFormat(" result.{0}.SetUnsafe({1});", fieldInfo.Name, string.Format(wrapper, string.Format("value.{0}", fieldInfo.Name))).AppendLine();
|
||||||
|
else if (string.IsNullOrEmpty(wrapper))
|
||||||
header.AppendFormat(" result.{0} = value.{0};", fieldInfo.Name).AppendLine();
|
header.AppendFormat(" result.{0} = value.{0};", fieldInfo.Name).AppendLine();
|
||||||
else
|
else
|
||||||
header.AppendFormat(" result.{0} = {1};", fieldInfo.Name, string.Format(wrapper, string.Format("value.{0}", fieldInfo.Name))).AppendLine();
|
header.AppendFormat(" result.{0} = {1};", fieldInfo.Name, string.Format(wrapper, string.Format("value.{0}", fieldInfo.Name))).AppendLine();
|
||||||
}
|
}
|
||||||
header.Append(" return result;").AppendLine();
|
header.Append(" return result;").AppendLine();
|
||||||
header.Append('}').AppendLine();
|
header.Append('}').AppendLine();
|
||||||
|
|
||||||
|
// Generate cleanup function for native resources
|
||||||
|
header.AppendLine();
|
||||||
|
header.AppendFormat("void FreeNative({0}& value)", fullName).AppendLine();
|
||||||
|
header.Append('{').AppendLine();
|
||||||
|
for (var i = 0; i < fields.Count; i++)
|
||||||
|
{
|
||||||
|
var fieldInfo = fields[i];
|
||||||
|
if (fieldInfo.IsStatic || fieldInfo.IsConstexpr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (fieldInfo.Type.Type == "AssetReference")
|
||||||
|
header.AppendFormat(" value.{0}.SetUnsafe(nullptr);", fieldInfo.Name).AppendLine();
|
||||||
|
}
|
||||||
|
header.Append('}').AppendLine();
|
||||||
header.AppendLine("}");
|
header.AppendLine("}");
|
||||||
}
|
}
|
||||||
else if (classInfo != null)
|
else if (classInfo != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user