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

Fix/build warnings 2024 09 15 #159

Open
wants to merge 31 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
31eb773
refactor: comment out private fields/variables that are not used
brmassa Sep 16, 2024
fa94257
refactor: comment out private fields that are not used
brmassa Sep 16, 2024
09f0d3f
fix: check of not null
brmassa Sep 16, 2024
f8f2ebe
fix: replace `async Task` for `void` for a method that do not use an…
brmassa Sep 16, 2024
f9cdd59
fix: switch for a SceneViewPreferences.Instance.GridType must contain…
brmassa Sep 16, 2024
2277029
fix: public static int OrderlessHash<T> must ensure that T is not nul…
brmassa Sep 16, 2024
90aef82
refactor: optimizing Prowl.Runtime.GUI.Spacing to reuse code
brmassa Sep 16, 2024
191e341
fix: assure that the t.Get is not null inside SerializedProperty.Merge
brmassa Sep 16, 2024
aea007d
fix: KeyFrame's CompareTo and Equals methods allowing null (it will b…
brmassa Sep 16, 2024
4497acf
fix: comment unused field and SceneMeshData.MeshData, that are never …
brmassa Sep 16, 2024
96f5777
fix: new InspectorWindow.CreateInstanceCustomEditor to optimized and …
brmassa Sep 16, 2024
3a622ba
fix: EngineObject.FindObjectsOfType should never return null
brmassa Sep 16, 2024
56e3ef1
fix: some arguments passed using `ref`instead the `in` used in the si…
brmassa Sep 16, 2024
9ac5c96
fix: use `await` to wait async method to finish
brmassa Sep 16, 2024
194948f
fix: rename Prowl.Editor.SelectHandler's Equals to EqualsFunc to avoi…
brmassa Sep 16, 2024
0e6c93e
fix: using new and override to avoid conflict with inherited methods
brmassa Sep 16, 2024
398b8e6
fix: unreachable code in Prowl.Runtime.PhysicsSetting
brmassa Sep 16, 2024
571d458
fix: variable is assigned but its value is never used
brmassa Sep 16, 2024
3f7fb2c
fix: check null before using it
brmassa Sep 16, 2024
3adbc9b
refactor: in `AssetsBrowserWindow.DrawFileEntry` no need to use hasSu…
brmassa Sep 16, 2024
d7a54f2
fix: CS8603 check for null before using it
brmassa Sep 16, 2024
93617ed
fix: several null checks
brmassa Sep 16, 2024
65d1ffb
fix: CS8605 checking possible null on casting
brmassa Sep 16, 2024
6e6f8fe
fix: call Dispose() directly is obsolete. Using .Destroy()
brmassa Sep 16, 2024
8eb1d48
fix: CS8625 assigning null to non-nullable fields. most fixes are jus…
brmassa Sep 16, 2024
e302443
fix: null checking
brmassa Sep 17, 2024
aca944c
refactor: readonly on several fields/properties that are never reassi…
brmassa Sep 17, 2024
792893f
refactor: some extra fixes
brmassa Sep 17, 2024
4c695f1
Revert "fix: call Dispose() directly is obsolete. Using .Destroy()"
brmassa Sep 17, 2024
100488f
fix: reverting replacement of Dispose() to Destroy()
brmassa Sep 17, 2024
0791469
Revert "refactor: readonly on several fields/properties that are neve…
brmassa Sep 19, 2024
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
27 changes: 16 additions & 11 deletions Prowl.Editor/Assets/AssetDatabase.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static AssetDirectoryCache GetRootFolderCache(int index)
public static void AddRootFolder(string rootFolder)
{
ArgumentException.ThrowIfNullOrEmpty(rootFolder);
ArgumentNullException.ThrowIfNull(Project.Active);

var rootPath = Path.Combine(Project.Active.ProjectPath, rootFolder);
var info = new DirectoryInfo(rootPath);
Expand Down Expand Up @@ -139,7 +140,7 @@ public static void Update(bool doUnload = true, bool forceCacheUpdate = false)
if (ProcessFile(file, out _))
toReimport.Add(file);
}
else if (!assetPathToMeta.TryGetValue(file, out var meta))
else if (!assetPathToMeta.TryGetValue(file, out _))
{
// File hasent changed but we dont have it in the cache, process it but dont reimport
Debug.Log("Asset Found: " + file);
Expand Down Expand Up @@ -168,7 +169,7 @@ public static void Update(bool doUnload = true, bool forceCacheUpdate = false)
cacheModified = true;
bool hasMeta = assetPathToMeta.TryGetValue(file, out var meta);

if (hasMeta)
if (hasMeta && meta is not null)
Copy link
Contributor

@michaelsakharov michaelsakharov Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably throw an error instead of continuing past as Meta being null here while hasMeta is true is pretty bad and should never occur.

{
assetPathToMeta.Remove(file);

Expand Down Expand Up @@ -248,7 +249,7 @@ static bool ProcessFile(string file, out bool metaOutdated)
{
// No meta file, create and import
var newMeta = new MetaFile(fileInfo);
if (newMeta.importer == null)
if (newMeta.Importer == null)
{
Debug.LogError($"No importer found for file:\n{fileInfo.FullName}");
return false;
Expand Down Expand Up @@ -351,17 +352,18 @@ public static bool Reimport(FileInfo assetFile, bool disposeExisting = true)
Debug.LogError($"No valid meta file found for asset: {ToRelativePath(assetFile)}");
return false;
}
if (meta.importer == null)
{
Debug.LogError($"No valid importer found for asset: {ToRelativePath(assetFile)}");
return false;
}
// TODO: FIXME: its always not null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they modify the meta file itself for example breaking or removing the importer, then load it into the editor, the Meta file will successfully load however Importer will be null. So this check is required for that edge case. Not sure why the compiler says it cant be null.

// if (meta.Importer == null)
// {
// Debug.LogError($"No valid importer found for asset: {ToRelativePath(assetFile)}");
// return false;
// }

// Import the asset
SerializedAsset ctx = new(meta.guid);
try
{
meta.importer.Import(ctx, assetFile);
meta.Importer.Import(ctx, assetFile);
}
catch (Exception e)
{
Expand Down Expand Up @@ -494,8 +496,11 @@ public static bool Reimport(FileInfo assetFile, bool disposeExisting = true)
{
var serializedAsset = SerializedAsset.FromSerializedAsset(serializedAssetPath.FullName);
serializedAsset.Guid = assetGuid;
serializedAsset.Main.AssetID = assetGuid;
serializedAsset.Main.FileID = 0;
if (serializedAsset.Main is not null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw an error, Main not existing is an entirely broken asset, main should always exist.

{
serializedAsset.Main.AssetID = assetGuid;
serializedAsset.Main.FileID = 0;
}
for (int i = 0; i < serializedAsset.SubAssets.Count; i++)
{
serializedAsset.SubAssets[i].AssetID = assetGuid;
Expand Down
4 changes: 2 additions & 2 deletions Prowl.Editor/Assets/AssetDatabase.FileOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static bool Rename(FileInfo file, string newName)
/// <summary>
/// Renames a folder.
/// </summary>
/// <param name="folder">The folder to rename.</param>
/// <param name="source">The folder to rename.</param>
/// <param name="newName">The new name of the folder.</param>
/// <returns>True if the folder was renamed successfully, false otherwise.</returns>
public static bool Rename(DirectoryInfo source, string newName)
Expand Down Expand Up @@ -143,7 +143,7 @@ public static bool Delete(FileInfo file)
/// <summary>
/// Deletes a folder.
/// </summary>
/// <param name="folder">The folder to delete.</param>
/// <param name="source">The folder to delete.</param>
/// <returns>True if the folder was deleted successfully, false otherwise.</returns>
public static bool Delete(DirectoryInfo source)
{
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Assets/AssetDatabase.Packages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public static async Task InstallPackage(string packageId, string version)
Update();
}

public static async Task UninstallPackage(string packageId, string version)
public static void UninstallPackage(string packageId, string version)
{
ArgumentNullException.ThrowIfNull(packageId, nameof(packageId));
ArgumentNullException.ThrowIfNull(version, nameof(version));
Expand Down
4 changes: 2 additions & 2 deletions Prowl.Editor/Assets/AssetDatabase.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static partial class AssetDatabase

#region Public Methods

public static bool PathToCachedNode(string path, out AssetDirectoryCache.DirNode node)
public static bool PathToCachedNode(string path, out AssetDirectoryCache.DirNode? node)
{
node = null;
foreach (var tuple in rootFolders)
Expand Down Expand Up @@ -239,7 +239,7 @@ public static void GenerateUniqueAssetPath(ref FileInfo file)
return result;
}

public static Type GetTypeOfAsset(Guid guid, ushort fileID)
public static Type? GetTypeOfAsset(Guid guid, ushort fileID)
{
if (assetGuidToMeta.TryGetValue(guid, out var meta))
if (meta.assetTypes.Length > fileID)
Expand Down
6 changes: 3 additions & 3 deletions Prowl.Editor/Assets/AssetDirectoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace Prowl.Editor.Assets;

public class AssetDirectoryCache(DirectoryInfo root)
{
public class DirNode(DirectoryInfo directory, DirNode parent)
public class DirNode(DirectoryInfo directory, DirNode? parent)
{
public DirectoryInfo Directory = directory;
public DirNode Parent = parent;
public DirNode? Parent = parent;
public List<DirNode> SubDirectories = [];
public List<FileNode> Files = [];
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public void Refresh()
_rootNode = BuildDirectoryTree(_rootDir, null);
}

private DirNode BuildDirectoryTree(DirectoryInfo directory, DirNode parent)
private DirNode BuildDirectoryTree(DirectoryInfo directory, DirNode? parent)
{
DirNode node = new(directory, parent);
try
Expand Down
52 changes: 25 additions & 27 deletions Prowl.Editor/Assets/ImporterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,25 @@ public static void GenerateLookUp()
extToIcon.Clear();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var type in assembly.GetTypes())
if (type != null)
{
var attribute = type.GetCustomAttribute<ImporterAttribute>();
if (attribute == null) continue;

foreach (var extRW in attribute.Extensions)
{
var attribute = type.GetCustomAttribute<ImporterAttribute>();
if (attribute == null) continue;

foreach (var extRW in attribute.Extensions)
{
var ext = extRW.ToLower();
// Make sure the Extension is formatted correctly '.png' 1 dot at start
if (ext[0] != '.') ext = '.' + ext;
// Check if has more then 1 '.'
if (ext.Count(x => x == '.') > 1) throw new Exception($"Extension {ext} is formatted incorrectly on importer: {type.Name}");

if (extToImporter.TryGetValue(ext, out var oldType))
Debug.LogError($"Asset Importer Overwritten. {ext} extension already in use by: {oldType.Name}, being overwritten by: {type.Name}");
extToImporter[ext] = type;
extToIcon[ext] = attribute.FileIcon;
extToGeneralType[ext] = attribute.GeneralType;
}
var ext = extRW.ToLower();
// Make sure the Extension is formatted correctly '.png' 1 dot at start
if (ext[0] != '.') ext = '.' + ext;
// Check if has more then 1 '.'
if (ext.Count(x => x == '.') > 1) throw new Exception($"Extension {ext} is formatted incorrectly on importer: {type.Name}");

if (extToImporter.TryGetValue(ext, out var oldType))
Debug.LogError($"Asset Importer Overwritten. {ext} extension already in use by: {oldType.Name}, being overwritten by: {type.Name}");
extToImporter[ext] = type;
extToIcon[ext] = attribute.FileIcon;
extToGeneralType[ext] = attribute.GeneralType;
}
}
}

[OnAssemblyUnload]
Expand Down Expand Up @@ -104,15 +103,14 @@ public static void GenerateLookUp()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var type in assembly.GetTypes())
if (type != null)
{
var attribute = type.GetCustomAttribute<CustomEditorAttribute>();
if (attribute == null) continue;

if (typeToEditor.TryGetValue(attribute.Type, out var oldType))
Debug.LogError($"Custom Editor Overwritten. {attribute.Type.Name} already has a custom Editor: {oldType.Name}, being overwritten by: {type.Name}");
typeToEditor[attribute.Type] = type;
}
{
var attribute = type.GetCustomAttribute<CustomEditorAttribute>();
if (attribute == null) continue;

if (typeToEditor.TryGetValue(attribute.Type, out var oldType))
Debug.LogError($"Custom Editor Overwritten. {attribute.Type.Name} already has a custom Editor: {oldType.Name}, being overwritten by: {type.Name}");
typeToEditor[attribute.Type] = type;
}
}

[OnAssemblyUnload]
Expand Down
5 changes: 3 additions & 2 deletions Prowl.Editor/Assets/Importers/AudioClipImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public class AudioClipEditor : ScriptedEditor

public override void OnEnable()
{
serialized = AssetDatabase.LoadAsset((target as MetaFile).AssetPath);
var metaFile = target as MetaFile ?? throw new Exception();
serialized = AssetDatabase.LoadAsset(metaFile.AssetPath) ?? throw new Exception();
}

public override void OnDisable()
Expand All @@ -140,7 +141,7 @@ public override void OnInspectorGUI()
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;

var importer = (AudioClipImporter)(target as MetaFile).importer;
var importer = (AudioClipImporter)(target as MetaFile).Importer;

try
{
Expand Down
4 changes: 2 additions & 2 deletions Prowl.Editor/Assets/Importers/FontImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Import(SerializedAsset ctx, FileInfo assetPath)
[CustomEditor(typeof(FontImporter))]
public class FontEditor : ScriptedEditor
{
static int start, end;
// static int start, end;
private readonly int numberOfProperties = 0;
public void InputFloat(string name, ref float val)
{
Expand Down Expand Up @@ -101,7 +101,7 @@ public override void OnInspectorGUI()
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;

var importer = (FontImporter)(target as MetaFile).importer;
var importer = (FontImporter)(target as MetaFile).Importer;

gui.CurrentNode.Layout(LayoutType.Column);

Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Assets/Importers/MaterialImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MaterialImporterEditor : ScriptedEditor
{
public override void OnInspectorGUI()
{
var importer = (MaterialImporter)(target as MetaFile).importer;
var importer = (MaterialImporter)(target as MetaFile).Importer;

try
{
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Assets/Importers/ModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public override void OnInspectorGUI()
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;

var importer = (ModelImporter)(target as MetaFile).importer;
var importer = (ModelImporter)(target as MetaFile).Importer;
var serialized = AssetDatabase.LoadAsset((target as MetaFile).AssetPath);

gui.CurrentNode.Layout(LayoutType.Column);
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Assets/Importers/TextureImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class TextureEditor : ScriptedEditor
{
public override void OnInspectorGUI()
{
var importer = (TextureImporter)(target as MetaFile).importer;
var importer = (TextureImporter)(target as MetaFile).Importer;

gui.CurrentNode.Layout(LayoutType.Column);

Expand Down
5 changes: 3 additions & 2 deletions Prowl.Editor/Assets/MetaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MetaFile
public string[] assetTypes = [];

public DateTime lastModified;
public ScriptedImporter importer;
public readonly ScriptedImporter Importer;
public List<Guid> dependencies;

/// <summary>Default constructor for MetaFile.</summary>
Expand All @@ -35,7 +35,8 @@ public MetaFile(FileInfo assetFile)
AssetPath = assetFile;
guid = Guid.NewGuid();
lastModified = assetFile.LastWriteTimeUtc;
importer = Activator.CreateInstance(importerType) as ScriptedImporter;
var importer = Activator.CreateInstance(importerType) as ScriptedImporter;
Importer = importer ?? throw new Exception();
}

/// <summary>Save the MetaFile to a specified file or default to the associated asset file with a ".meta" extension.</summary>
Expand Down
6 changes: 3 additions & 3 deletions Prowl.Editor/Editor/AssetsBrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,20 @@ public void RenderEntry(ref int index, AssetDirectoryCache.FileNode entry)
var interact = gui.GetInteractable();
AssetsTreeWindow.HandleFileClick(-1, interact, entry, i, true);

DrawFileEntry(index++, entry.File, interact, true, subAssets[i]);
DrawFileEntry(index++, entry.File, interact, subAssets[i]);
}
}
}
}

private void DrawFileEntry(int index, FileSystemInfo entry, Interactable interact, bool hasSubAsset = false, AssetDatabase.SubAssetCache? subAsset = null)
private void DrawFileEntry(int index, FileSystemInfo entry, Interactable interact, AssetDatabase.SubAssetCache? subAsset = null)
{
var rect = gui.CurrentNode.LayoutData.Rect;
//if (hasSubAsset)
// rect.Expand(-10);
var entrySize = rect.width;

gui.Tooltip(hasSubAsset ? subAsset.Value.name : entry.FullName);
gui.Tooltip(subAsset is not null ? subAsset.Value.name : entry.FullName);

var color = EditorStylePrefs.Instance.Borders;
if (entry is FileInfo f)
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Editor/AssetsTreeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected override void Draw()
}
}

public static void DrawContextMenu(FileSystemInfo? fileInfo, DirectoryInfo? directory = null, bool fromAssetBrowser = false, LayoutNode popupHolder = null)
public static void DrawContextMenu(FileSystemInfo? fileInfo, DirectoryInfo? directory = null, bool fromAssetBrowser = false, LayoutNode? popupHolder = null)
{
bool closePopup = false;

Expand Down
30 changes: 16 additions & 14 deletions Prowl.Editor/Editor/Docking/DockContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ namespace Prowl.Editor.Docking;

public class DockContainer
{
public DockNode Root = new DockNode();
private Vector2 PaddedMins => new Vector2(0, 0);
public DockNode Root = new();
private Vector2 PaddedMins => new(0, 0);

public void Update(Rect root)
{
Root.UpdateRecursive(root.Min, root.Max);
}

public DockNode TraceLeaf(double x, double y)
public DockNode? TraceLeaf(double x, double y)
{
x -= PaddedMins.x;
y -= PaddedMins.y;

return Root.TraceLeaf(x, y);
}

public DockPlacement GetPlacement(double x, double y, out List<Rect> possibleAreas, out Rect hovered)
public DockPlacement GetPlacement(double x, double y, out List<Rect>? possibleAreas, out Rect hovered)
{
possibleAreas = null;
hovered = Rect.Zero;
Expand All @@ -38,21 +38,23 @@ public DockPlacement GetPlacement(double x, double y, out List<Rect> possibleAre
return default;

Vector2 cen = (leaf.Mins + leaf.Maxs) * 0.5f;
Vector2 size = new Vector2(100, 100);
Vector2 size = new(100, 100);
// TODO: Why do we need to remove half of the size? Shouldn't ((min + max) / 2) be the center already?
cen.x -= size.x / 2;
cen.y -= size.y / 2;
Rect main = new Rect(cen, size);
Rect main = new(cen, size);

Rect left = new Rect(cen - new Vector2(size.x + 5, 0), size);
Rect right = new Rect(cen + new Vector2(size.x + 5, 0), size);
Rect top = new Rect(cen - new Vector2(0, size.y + 5), size);
Rect bottom = new Rect(cen + new Vector2(0, size.y + 5), size);
Rect left = new(cen - new Vector2(size.x + 5, 0), size);
Rect right = new(cen + new Vector2(size.x + 5, 0), size);
Rect top = new(cen - new Vector2(0, size.y + 5), size);
Rect bottom = new(cen + new Vector2(0, size.y + 5), size);
possibleAreas = [main, left, right, top, bottom];

DockPlacement placement = new DockPlacement();
placement.Leaf = leaf;
placement.PolygonVerts = new Vector2[4];
DockPlacement placement = new()
{
Leaf = leaf,
PolygonVerts = new Vector2[4]
};

while (true)
{
Expand Down Expand Up @@ -318,7 +320,7 @@ public bool DetachWindow(EditorWindow window)

if (leaf.LeafWindows.Count == 0)
{
DockNode parent = FindParent(leaf);
DockNode? parent = FindParent(leaf);
if (parent != null)
{
DockNode neighborNode;
Expand Down
Loading
Loading