diff --git a/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs b/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs index e6868e4fd..1516cce0c 100644 --- a/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs +++ b/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs @@ -25,12 +25,12 @@ namespace FlaxEditor.Modules.SourceCodeEditing { } - private static bool CheckFunc(ScriptType type) + private static bool CheckFunc(ScriptType scriptType) { - if (!type.IsPublic) + if (scriptType.IsStatic || scriptType.IsGenericType || !scriptType.IsPublic || scriptType.HasAttribute(typeof(HideInEditorAttribute), true)) return false; var objectType = new ScriptType(typeof(FlaxEngine.Object)); - return type.IsEnum || type == objectType || objectType.IsAssignableFrom(type); + return scriptType.IsEnum || objectType.IsAssignableFrom(scriptType); } /// diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 7a136ea38..4d0ab8e63 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -288,12 +288,12 @@ namespace FlaxEditor.Surface /// /// Don't call it too often. It does memory allocation and iterates over the surface controls to find comments in the graph. /// - public List Comments => _context.Comments; + public List Comments => _context?.Comments; /// /// The current surface context nodes collection. Read-only. /// - public List Nodes => _context.Nodes; + public List Nodes => _context?.Nodes; /// /// The surface node descriptors collection. diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index fe146dcb2..a0a84ae0f 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -188,12 +188,13 @@ namespace FlaxEditor.Utilities public static void DirectoryCopy(string srcDirectoryPath, string dstDirectoryPath, bool copySubDirs = true, bool overrideFiles = false) { var dir = new DirectoryInfo(srcDirectoryPath); - if (!dir.Exists) - { throw new DirectoryNotFoundException("Missing source directory to copy. " + srcDirectoryPath); - } + DirectoryCopy(dir, dstDirectoryPath, copySubDirs, overrideFiles); + } + private static void DirectoryCopy(DirectoryInfo dir, string dstDirectoryPath, bool copySubDirs = true, bool overrideFiles = false) + { if (!Directory.Exists(dstDirectoryPath)) { Directory.CreateDirectory(dstDirectoryPath); @@ -212,7 +213,7 @@ namespace FlaxEditor.Utilities for (int i = 0; i < dirs.Length; i++) { string tmp = Path.Combine(dstDirectoryPath, dirs[i].Name); - DirectoryCopy(dirs[i].FullName, tmp, true, overrideFiles); + DirectoryCopy(dirs[i], tmp, true, overrideFiles); } } } @@ -225,11 +226,7 @@ namespace FlaxEditor.Utilities /// The structure. public static T ByteArrayToStructure(byte[] bytes) where T : struct { - // #stupid c# - GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); - T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); - handle.Free(); - return stuff; + return (T)ByteArrayToStructure(bytes, typeof(T)); } /// @@ -255,10 +252,7 @@ namespace FlaxEditor.Utilities /// The result. public static void ByteArrayToStructure(byte[] bytes, out T result) where T : struct { - // #stupid c# - GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); - result = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); - handle.Free(); + result = (T)ByteArrayToStructure(bytes, typeof(T)); } /// @@ -269,14 +263,7 @@ namespace FlaxEditor.Utilities /// The bytes array that contains a structure data. public static byte[] StructureToByteArray(ref T value) where T : struct { - // #stupid c# - int size = Marshal.SizeOf(typeof(T)); - byte[] arr = new byte[size]; - IntPtr ptr = Marshal.AllocHGlobal(size); - Marshal.StructureToPtr(value, ptr, true); - Marshal.Copy(ptr, arr, 0, size); - Marshal.FreeHGlobal(ptr); - return arr; + return StructureToByteArray(value, typeof(void)); } /// diff --git a/Source/Editor/Utilities/VariantUtils.cs b/Source/Editor/Utilities/VariantUtils.cs index d30cb26af..d09228c37 100644 --- a/Source/Editor/Utilities/VariantUtils.cs +++ b/Source/Editor/Utilities/VariantUtils.cs @@ -418,6 +418,8 @@ namespace FlaxEditor.Utilities { if (type == null) throw new Exception("Missing structure type of the Variant."); + if (!type.IsStructure()) + throw new Exception($"Invalid type {type.FullName} used as a structure."); var data = stream.ReadBytes(stream.ReadInt32()); return Utils.ByteArrayToStructure(data, type); } diff --git a/Source/Editor/Windows/VisualScriptDebuggerWindow.cs b/Source/Editor/Windows/VisualScriptDebuggerWindow.cs index f91d0cea9..d152363ed 100644 --- a/Source/Editor/Windows/VisualScriptDebuggerWindow.cs +++ b/Source/Editor/Windows/VisualScriptDebuggerWindow.cs @@ -338,9 +338,12 @@ namespace FlaxEditor.Windows FlaxEngine.Scripting.RunOnUpdate(() => { vsWindow.Surface.NodeBreakpointEdited += OnSurfaceNodeBreakpointEdited; - foreach (var node in vsWindow.Surface.Nodes) - if (node.Breakpoint.Set) - OnSurfaceNodeBreakpointEdited(node); + if (vsWindow.Surface.Nodes != null) + { + foreach (var node in vsWindow.Surface.Nodes) + if (node.Breakpoint.Set) + OnSurfaceNodeBreakpointEdited(node); + } }); } } diff --git a/Source/Engine/Serialization/Stream.cpp b/Source/Engine/Serialization/Stream.cpp index 21d10f987..ba6281cf3 100644 --- a/Source/Engine/Serialization/Stream.cpp +++ b/Source/Engine/Serialization/Stream.cpp @@ -348,9 +348,7 @@ void ReadStream::ReadVariant(Variant* data) LOG(Error, "Invalid Variant {2} data length {0}. Expected {1} bytes from stream.", data->AsBlob.Length, length, data->Type.ToString()); // Skip those bytes - void* ptr = Allocator::Allocate(length); - ReadBytes(ptr, length); - Allocator::Free(ptr); + SetPosition(GetPosition() + length); } break; }