/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Camera, AiCamera}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue != IntPtr.Zero && freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Metadata, AiMetadata}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiMetadata aiMetadata = MemoryHelper.MarshalStructure <AiMetadata>(nativeValue); if (aiMetadata.keys != IntPtr.Zero) { MemoryHelper.FreeMemory(aiMetadata.keys); } if (aiMetadata.Values != IntPtr.Zero) { AiMetadataEntry[] entries = MemoryHelper.FromNativeArray <AiMetadataEntry>(aiMetadata.Values, (int)aiMetadata.NumProperties); foreach (AiMetadataEntry entry in entries) { if (entry.Data != IntPtr.Zero) { MemoryHelper.FreeMemory(entry.Data); } } MemoryHelper.FreeMemory(aiMetadata.Values); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{NodeAnimationChannel, AiNodeAnim}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiNodeAnim aiNodeAnim = MemoryHelper.Read <AiNodeAnim>(nativeValue); if (aiNodeAnim.NumPositionKeys > 0 && aiNodeAnim.PositionKeys != IntPtr.Zero) { MemoryHelper.FreeMemory(aiNodeAnim.PositionKeys); } if (aiNodeAnim.NumRotationKeys > 0 && aiNodeAnim.RotationKeys != IntPtr.Zero) { MemoryHelper.FreeMemory(aiNodeAnim.RotationKeys); } if (aiNodeAnim.NumScalingKeys > 0 && aiNodeAnim.ScalingKeys != IntPtr.Zero) { MemoryHelper.FreeMemory(aiNodeAnim.ScalingKeys); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Node, AiNode}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiNode aiNode = MemoryHelper.Read <AiNode>(nativeValue); if (aiNode.NumMeshes > 0 && aiNode.Meshes != IntPtr.Zero) { MemoryHelper.FreeMemory(aiNode.Meshes); } if (aiNode.NumChildren > 0 && aiNode.Children != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiNode>(aiNode.Children, (int)aiNode.NumChildren, FreeNative, true); } if (aiNode.MetaData != IntPtr.Zero) { Metadata.FreeNative(aiNode.MetaData, true); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{MeshAnimationAttachment, AiAnimMesh}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static unsafe void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiAnimMesh aiAnimMesh = *((AiAnimMesh *)nativeValue); if (aiAnimMesh.NumVertices > 0) { if (aiAnimMesh.Vertices != IntPtr.Zero) { MemoryHelper.FreeMemory(aiAnimMesh.Vertices); } if (aiAnimMesh.Normals != IntPtr.Zero) { MemoryHelper.FreeMemory(aiAnimMesh.Normals); } if (aiAnimMesh.Tangents != IntPtr.Zero) { MemoryHelper.FreeMemory(aiAnimMesh.Tangents); } if (aiAnimMesh.BiTangents != IntPtr.Zero) { MemoryHelper.FreeMemory(aiAnimMesh.BiTangents); } //Vertex Color channels for (int i = 0; i < aiAnimMesh.Colors.Length; i++) { IntPtr colorPtr = aiAnimMesh.Colors[i]; if (colorPtr != IntPtr.Zero) { MemoryHelper.FreeMemory(colorPtr); } } //Texture coordinate channels for (int i = 0; i < aiAnimMesh.TextureCoords.Length; i++) { IntPtr texCoordsPtr = aiAnimMesh.TextureCoords[i]; if (texCoordsPtr != IntPtr.Zero) { MemoryHelper.FreeMemory(texCoordsPtr); } } } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Mesh, AiMesh}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) return; AiMesh aiMesh = MemoryHelper.Read<AiMesh>(nativeValue); if (aiMesh.NumVertices > 0) { if (aiMesh.Vertices != IntPtr.Zero) MemoryHelper.FreeMemory(aiMesh.Vertices); if (aiMesh.Normals != IntPtr.Zero) MemoryHelper.FreeMemory(aiMesh.Normals); if (aiMesh.Tangents != IntPtr.Zero) MemoryHelper.FreeMemory(aiMesh.Tangents); if (aiMesh.BiTangents != IntPtr.Zero) MemoryHelper.FreeMemory(aiMesh.BiTangents); //Vertex Color channels for (int i = 0; i < aiMesh.Colors.Length; i++) { IntPtr colorPtr = aiMesh.Colors[i]; if (colorPtr != IntPtr.Zero) MemoryHelper.FreeMemory(colorPtr); } //Texture coordinate channels for (int i = 0; i < aiMesh.TextureCoords.Length; i++) { IntPtr texCoordsPtr = aiMesh.TextureCoords[i]; if (texCoordsPtr != IntPtr.Zero) MemoryHelper.FreeMemory(texCoordsPtr); } } //Faces if (aiMesh.NumFaces > 0 && aiMesh.Faces != IntPtr.Zero) MemoryHelper.FreeNativeArray<AiFace>(aiMesh.Faces, (int)aiMesh.NumFaces, Face.FreeNative); //Bones if (aiMesh.NumBones > 0 && aiMesh.Bones != IntPtr.Zero) MemoryHelper.FreeNativeArray<AiBone>(aiMesh.Bones, (int)aiMesh.NumBones, Bone.FreeNative, true); //Attachment meshes if (aiMesh.NumAnimMeshes > 0 && aiMesh.AnimMeshes != IntPtr.Zero) MemoryHelper.FreeNativeArray<AiAnimMesh>(aiMesh.AnimMeshes, (int)aiMesh.NumAnimMeshes, MeshAnimationAttachment.FreeNative, true); if (freeNative) MemoryHelper.FreeMemory(nativeValue); }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Scene, AiScene}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiScene aiScene = MemoryHelper.Read <AiScene>(nativeValue); if (aiScene.NumMaterials > 0 && aiScene.Materials != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiMaterial>(aiScene.Materials, (int)aiScene.NumMaterials, Material.FreeNative, true); } if (aiScene.RootNode != IntPtr.Zero) { Node.FreeNative(aiScene.RootNode, true); } if (aiScene.NumMeshes > 0 && aiScene.Meshes != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiMesh>(aiScene.Meshes, (int)aiScene.NumMeshes, Mesh.FreeNative, true); } if (aiScene.NumLights > 0 && aiScene.Lights != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiLight>(aiScene.Lights, (int)aiScene.NumLights, Light.FreeNative, true); } if (aiScene.NumCameras > 0 && aiScene.Cameras != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiCamera>(aiScene.Cameras, (int)aiScene.NumCameras, Camera.FreeNative, true); } if (aiScene.NumTextures > 0 && aiScene.Textures != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiTexture>(aiScene.Textures, (int)aiScene.NumTextures, EmbeddedTexture.FreeNative, true); } if (aiScene.NumAnimations > 0 && aiScene.Animations != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiAnimation>(aiScene.Animations, (int)aiScene.NumAnimations, Animation.FreeNative, true); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing">True to release both managed and unmanaged resources; False to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!m_isDisposed) { if (m_logstreamPtr != IntPtr.Zero) { MemoryHelper.FreeMemory(m_logstreamPtr); m_logstreamPtr = IntPtr.Zero; } if (disposing) { m_assimpCallback = null; } m_isDisposed = true; } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing">True to release both managed and unmanaged resources; False to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!m_isDisposed) { if (m_fileIOPtr != IntPtr.Zero) { MemoryHelper.FreeMemory(m_fileIOPtr); m_fileIOPtr = IntPtr.Zero; } if (disposing) { m_openProc = null; m_closeProc = null; CloseAllFiles(); } m_isDisposed = true; } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{MeshAnimationChannel, AiMeshAnim}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiMeshAnim aiMeshAnim = MemoryHelper.Read <AiMeshAnim>(nativeValue); if (aiMeshAnim.NumKeys > 0 && aiMeshAnim.Keys != IntPtr.Zero) { MemoryHelper.FreeMemory(aiMeshAnim.Keys); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Bone, AiBone}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static unsafe void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiBone aiBone = *((AiBone *)nativeValue); if (aiBone.NumWeights > 0 && aiBone.Weights != IntPtr.Zero) { MemoryHelper.FreeMemory(aiBone.Weights); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{EmbeddedTexture, AiTexture}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiTexture aiTexture = MemoryHelper.Read <AiTexture>(nativeValue); if (aiTexture.Width > 0 && aiTexture.Data != IntPtr.Zero) { MemoryHelper.FreeMemory(aiTexture.Data); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Face, AiFace}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiFace aiFace = MemoryHelper.Read <AiFace>(nativeValue); if (aiFace.NumIndices > 0 && aiFace.Indices != IntPtr.Zero) { MemoryHelper.FreeMemory(aiFace.Indices); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Bone, AiBone}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiBone aiBone = MemoryHelper.Read <AiBone>(nativeValue); int numWeights = MemoryHelper.Read <int>(MemoryHelper.AddIntPtr(nativeValue, MemoryHelper.SizeOf <AiString>())); IntPtr weightsPtr = MemoryHelper.AddIntPtr(nativeValue, MemoryHelper.SizeOf <AiString>() + sizeof(uint)); if (aiBone.NumWeights > 0 && aiBone.Weights != IntPtr.Zero) { MemoryHelper.FreeMemory(aiBone.Weights); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing">True to release both managed and unmanaged resources; False to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!m_isDiposed) { if (m_filePtr != IntPtr.Zero) { MemoryHelper.FreeMemory(m_filePtr); m_filePtr = IntPtr.Zero; } if (disposing) { m_writeProc = null; m_readProc = null; m_tellProc = null; m_fileSizeProc = null; m_seekProc = null; m_flushProc = null; } m_isDiposed = true; } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{Animation, AiAnimation}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiAnimation aiAnimation = MemoryHelper.Read <AiAnimation>(nativeValue); if (aiAnimation.NumChannels > 0 && aiAnimation.Channels != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiNodeAnim>(aiAnimation.Channels, (int)aiAnimation.NumChannels, NodeAnimationChannel.FreeNative, true); } if (aiAnimation.NumMeshChannels > 0 && aiAnimation.MeshChannels != IntPtr.Zero) { MemoryHelper.FreeNativeArray <AiMeshAnim>(aiAnimation.MeshChannels, (int)aiAnimation.NumMeshChannels, MeshAnimationChannel.FreeNative, true); } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }
/// <summary> /// Frees unmanaged memory created by <see cref="IMarshalable{MeshAnimationAttachment, AiAnimMesh}.ToNative"/>. /// </summary> /// <param name="nativeValue">Native value to free</param> /// <param name="freeNative">True if the unmanaged memory should be freed, false otherwise.</param> public static void FreeNative(IntPtr nativeValue, bool freeNative) { if (nativeValue == IntPtr.Zero) { return; } AiMesh aiMesh = MemoryHelper.MarshalStructure <AiMesh>(nativeValue); if (aiMesh.NumVertices > 0) { if (aiMesh.Vertices != IntPtr.Zero) { MemoryHelper.FreeMemory(aiMesh.Vertices); } if (aiMesh.Normals != IntPtr.Zero) { MemoryHelper.FreeMemory(aiMesh.Normals); } if (aiMesh.Tangents != IntPtr.Zero) { MemoryHelper.FreeMemory(aiMesh.Tangents); } if (aiMesh.BiTangents != IntPtr.Zero) { MemoryHelper.FreeMemory(aiMesh.BiTangents); } //Vertex Color channels IntPtr[] colors = aiMesh.Colors; if (colors != null) { for (int i = 0; i < colors.Length; i++) { IntPtr colorPtr = colors[i]; if (colorPtr != IntPtr.Zero) { MemoryHelper.FreeMemory(colorPtr); } } } //Texture coordinate channels IntPtr[] texCoords = aiMesh.TextureCoords; if (texCoords != null) { for (int i = 0; i < texCoords.Length; i++) { IntPtr texCoordsPtr = texCoords[i]; if (texCoordsPtr != IntPtr.Zero) { MemoryHelper.FreeMemory(texCoordsPtr); } } } } if (freeNative) { MemoryHelper.FreeMemory(nativeValue); } }