-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: development
Are you sure you want to change the base?
Fix/build warnings 2024 09 15 #159
Conversation
CS8629 and some other fixes |
CS8603 and some CS8601 down to 406 warnings |
down to 357 warnings |
It might make more sense to disable the Readonly warning. For example almost all the Components/Monobehaviour shouldn't have readonly fields, since the whole point of them are settings for the components. |
Understand the point. Some thoughts:
In general, Paths forward:
|
… async internally
… all possibilities
…l because it will be the index of a dictionary
…e dealt internally)
…bset. just check if `subAsset` is not null
…t settings them nullable
…gned (typical for collections)
This reverts commit 1dd6a73.
3e2af96
to
100488f
Compare
The issue with switching to Properties is that moves away from the Unity API. Unity doesn't really even support properties-only fields, our serializer also doesn't handle them properly and it would be a reasonably big change for newcomers to c# who only know c# through Unity. I think the read-only one makes sense to remove for the time being, What do you think @sinnwrig |
hehe yeah im one of those unity C# only people :P |
One thought I have is maybe not worrying about Unity only devs? We would only be perpetuating the problem. |
…r reassigned (typical for collections)" This reverts commit aca944c.
It's problem going to bite us in the future, but for the time being, I'm reverting it. There are still a lot (200+) other warning to attack. |
I mean a huge part of prowl is to be a unity alternative, so it's main audience by far will be unity devs. On top of the fact that it's not really a huge problem to perpetuate in the first place. Its less a problem and more a design choice in my opinion. |
ok. Commit reverted. I believe Unity did some choices back in old days due lack of resources. Joachim (Unity ttech chief back then) repeatedly said there are several design mistakes that now they kinda have to live with. Their serializer is sub-par. Sirenix (Odin) serializer is much more capable. Using public mutable fields is a very bad practice. Basically all Static Analyzers will complain: Visual Studio, Rider, Codacy, Qodana, etc. Sicne drag-and-drop replacement is virtually impossible, I believe we could have peace of mind on taking some things in other direction. As long it's well documented and explained to users. |
The readonly warnings should only be appearing because of C# style recommendations, correct? If so, it would probably be feasible to revert the warnings back to suggestions in the .editorconfig, since the compiler can't be aware of how a user and the serializer might interact with it. On top of that, the warning seems a bit like premature optimization, since the performance boost gained by setting fields to readonly is negligible in most cases unless it's in perf. critical code, in which case it can be optimized manually later down the line. |
@@ -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) |
There was a problem hiding this comment.
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.
Debug.LogError($"No valid importer found for asset: {ToRelativePath(assetFile)}"); | ||
return false; | ||
} | ||
// TODO: FIXME: its always not null |
There was a problem hiding this comment.
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.
@@ -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) |
There was a problem hiding this comment.
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.
@@ -170,7 +170,7 @@ private void DrawPackageList() | |||
} | |||
} | |||
|
|||
private void DrawPackageDetails() | |||
private async void DrawPackageDetails() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be mistaken, But does making this method Async mean that the methods that call it continue onwards before this method finishes it's execution?
To my understanding, that's how Async methods work when executed from a synchronous caller. This would be problematic here, as it would change when/how this UI code executes, which could break the UI in unpredictable ways.
I believe the original intentional was calls to InstallPackage are not awaited and can execute at a later time asynchronous, but DrawPackageDetails in particular needs to execute and finish immediately on call for UI.
@@ -12,9 +12,9 @@ public class Double_PropertyDrawer : PropertyDrawer | |||
public override double MinWidth => EditorStylePrefs.Instance.ItemSize * 2; | |||
public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object? value) | |||
{ | |||
double val = (double)value; | |||
double val = value is double v ? v : double.NaN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NaN here might be a bit dangerous, just 0 or an exception would probably be ideal.
If this were to break and set things to NaN it would set users settings and values to NaN, which could spread and corrupt projects.
protected override int GetCount(Array value) => value.Length; | ||
protected override object GetElement(Array value, int index) => value.GetValue(index); | ||
protected override object GetElement(Array value, int index) => value.GetValue(index)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be able to return null, so probably saver to make these methods nullabes. since its just an array GetValue for the inspector anything inside can be null which should be supported by the editor.
@@ -308,7 +307,7 @@ public static void SaveScene() | |||
return; | |||
} | |||
|
|||
if (AssetDatabase.TryGetFile(scene.AssetID, out var file)) | |||
if (AssetDatabase.TryGetFile(scene.AssetID, out var file) && file is not null) |
There was a problem hiding this comment.
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 exception if the file is Null, since it means the asset doesn't actually exist, yet its ID is in the database, this suggests a bigger problem with the Asset Database,
On the public mutable fields, it seems a bit harsh to remove them completely because of bad design practice, since for many cases, having simple, raw, exposed values without a get/set (even if it's auto-implemented) is useful. If it's possible, it would eventually be nice to support [SerializeField] on property get/set. However, for most cases, something like [field:SerializeField] attribute is good enough to let the serializer get to an auto-implemented property. In addition, while it might be good in the context of an organizational project, the engine should not be enforcing good practice or style on users, and the decision should ideally be the developer's to follow their own style guides and practices. |
Attacking #158
fixes for:
CS0108: 4
CS4014: 4
CS9191: 3
CS8619: 3
CS0649: 3
CS8765: 2
CS8767: 2
CS8620: 2
CS0659: 1
CS0661: 1
CS8714: 1
CS8607: 1
CS8509: 1
CS1998: 1
from 529 to 467 compilation warnings (not considering
DotCast
norVeldrid
)