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

Error Reporting System #124

Merged
merged 44 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
653b4a8
feat: initial commit for Error Reporting System
anatawa12 Apr 30, 2023
326bcd6
chore: make ErrorReportingSystem depends on VRCSDKA
anatawa12 Apr 30, 2023
e034fda
chore: temporally disable serializing to json
anatawa12 Apr 30, 2023
f12457d
chore: remove logo from error reporting window
anatawa12 Apr 30, 2023
bde2e14
chore: remove ComponentValidation implementation
anatawa12 Apr 30, 2023
91523db
chore: use CL4EE
anatawa12 Apr 30, 2023
fb4e7b6
chore: replace Utils
anatawa12 Apr 30, 2023
b27ef22
chore: temporally disable callbacks
anatawa12 Apr 30, 2023
0c0aece
chore: move MenuItem
anatawa12 Apr 30, 2023
7daf97d
chore: add error reporter runtime module
anatawa12 May 1, 2023
8809b00
chore: move ErrorLog to Runtime module
anatawa12 May 1, 2023
961b20e
fix: reference to editor only functions
anatawa12 May 1, 2023
940c839
feat: add I(Self)StaticValidated and ComponentValidation system
anatawa12 May 1, 2023
8890220
chore: make ErrorLog constructor public
anatawa12 May 1, 2023
e71d144
fix: multi child type error is not localized
anatawa12 May 1, 2023
679c5bb
fix: register validator doesn't accept classes not implements ISelfSt…
anatawa12 May 1, 2023
d3ff9b1
fix: use CL4EE for specific assembly
anatawa12 May 1, 2023
08c39de
feat: add ErrorLog construction methods
anatawa12 May 1, 2023
5a30c10
chore: use Error Reporting System on MergePhysBone
anatawa12 May 1, 2023
0de13e3
chore: redraw error report window on the time component is changed
anatawa12 May 1, 2023
a6796f6
fix: style sheet name conflict
anatawa12 May 2, 2023
d24f1d2
Merge branch 'master' into error-reporting-system
anatawa12 May 2, 2023
42bba99
fix: parentDiffer eror is not reported on the Error Reporter
anatawa12 May 2, 2023
2a25558
chore: add ReportingObjects and make ReportingObject public
anatawa12 May 2, 2023
2b92f0b
chore: use BuildReport.ReportingObject in processors
anatawa12 May 2, 2023
db3c957
chore: move BuildReport to Editor module
anatawa12 May 3, 2023
800d0c1
feat: initialize ErrorReporting themself
anatawa12 May 3, 2023
d9cba77
chore: wrap with BuildReport.ReportingOnAvatar
anatawa12 May 3, 2023
7ed11bc
chore: wrap with BuildReport.ReportingOnAvatar in EarlyOptimizerProce…
anatawa12 May 3, 2023
0226e3d
fix: internal error is not localized
anatawa12 May 4, 2023
68c9784
chore: remove throwing exception in MergePhysBoneProcessor
anatawa12 May 4, 2023
45a2b3b
fix: fix RegisterValidator should accept IEnumerable
anatawa12 May 4, 2023
db8bb8c
chore: add Validator for MergeSkinnedMeshEditor
anatawa12 May 4, 2023
46de65c
chore: add Validator for AvatarGlobalComponents
anatawa12 May 4, 2023
e01e81a
fix: fix UnusedBonesByReferencesTool is a AvatarGlobalComponent
anatawa12 May 4, 2023
7412843
Merge branch 'master' into error-reporting-system
anatawa12 May 4, 2023
98c24fc
docs(changelog): add Error Reporting System
anatawa12 May 4, 2023
308ac11
chore: add the component to referencedObjects out of validator callback
anatawa12 May 5, 2023
b200285
chore: remake ObjectRef
anatawa12 May 5, 2023
5d70509
chore: remake ObjectRefLookupCache
anatawa12 May 5, 2023
6414fba
chore: save report to library to keep info after assembly reload
anatawa12 May 5, 2023
2633169
Merge branch 'master' into error-reporting-system
anatawa12 May 5, 2023
ba8e99a
fix: runtime module of ErrorReporter depends on unity engine
anatawa12 May 5, 2023
7437dec
fix: remove GetCurrentReportActiveReferences in Utils
anatawa12 May 5, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Error Reporting System `#124`
- This adds window shows errors on build
- This is based on Modular Avatar's Error Reporting Window. thanks `@bdunderscore`

### Changed

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Error Reporting System `#124`
- This adds window shows errors on build
- This is based on Modular Avatar's Error Reporting Window. thanks `@bdunderscore`

### Changed

Expand Down
13 changes: 13 additions & 0 deletions Editor/AvatarGlobalComponentEditorBase.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
using Anatawa12.AvatarOptimizer.ErrorReporting;
using CustomLocalization4EditorExtension;
using UnityEditor;
using UnityEngine;
using VRC.Core;
using VRC.SDK3.Avatars.Components;

namespace Anatawa12.AvatarOptimizer
{
[InitializeOnLoad]
abstract class AvatarGlobalComponentEditorBase : AvatarTagComponentEditorBase
{
static AvatarGlobalComponentEditorBase()
{
ComponentValidation.RegisterValidator<AvatarGlobalComponent>(component =>
{
if (!component.GetComponent<VRCAvatarDescriptor>())
return new[] { ErrorLog.Validation("AvatarGlobalComponent:NotOnAvatarDescriptor") };
return null;
});
}

protected override void OnInspectorGUIInner()
{
if (!((Component)serializedObject.targetObject).GetComponent<VRCAvatarDescriptor>())
Expand Down
137 changes: 136 additions & 1 deletion Editor/MergePhysBoneEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using CustomLocalization4EditorExtension;
using JetBrains.Annotations;
using UnityEditor;
Expand Down Expand Up @@ -371,7 +372,7 @@ protected override void TransformSection() {
EditorGUILayout.LabelField("Multi Child Type", "Must be Ignore");
var multiChildType = _sourcePhysBone.FindProperty("multiChildType");
if (multiChildType.enumValueIndex != 0 || multiChildType.hasMultipleDifferentValues)
EditorGUILayout.HelpBox("Some PysBone has multi child type != Ignore", MessageType.Error);
EditorGUILayout.HelpBox(CL4EE.Tr("MergePhysBone:error:multiChildType"), MessageType.Error);
}
protected override void OptionParameter() {
EditorGUILayout.PropertyField(_mergedPhysBone.FindProperty("parameter"));
Expand Down Expand Up @@ -786,4 +787,138 @@ private static int PopupNoIndent(Rect position, int selectedIndex, string[] disp
return result;
}
}

[InitializeOnLoad]
sealed class MergePhysBoneValidator : MergePhysBoneEditorModificationUtils
{
private readonly List<ErrorLog> _errorLogs;
private readonly List<string> _differProps = new List<string>();
private readonly MergePhysBone _mergePhysBone;

static MergePhysBoneValidator()
{
ComponentValidation.RegisterValidator<MergePhysBone>(Validate);
}

private static List<ErrorLog> Validate(MergePhysBone mergePhysBone)
{
var list = new List<ErrorLog>();
if (mergePhysBone.makeParent && mergePhysBone.transform.childCount != 0)
list.Add(ErrorLog.Validation("MergePhysBone:error:makeParentWithChildren", mergePhysBone));

new MergePhysBoneValidator(list, mergePhysBone).DoProcess();

return list;
}

public MergePhysBoneValidator(List<ErrorLog> errorLogs, MergePhysBone mergePhysBone)
: base(new SerializedObject(mergePhysBone))
{
_errorLogs = errorLogs;
_mergePhysBone = mergePhysBone;
}

private static void Void()
{
}

protected override void BeginPbConfig() => Void();
protected override bool BeginSection(string name, string docTag) => true;
protected override void EndSection() => Void();
protected override void EndPbConfig() {
if (_differProps.Count != 0)
{
_errorLogs.Add(ErrorLog.Validation("MergePhysBone:error:differValues",
new[] { string.Join(", ", _differProps) }));
}
}

protected override void NoSource() =>
_errorLogs.Add(ErrorLog.Validation("MergePhysBone:error:noSources"));

protected override void TransformSection()
{
if (!_mergePhysBone.makeParent)
{
var differ = _sourcePhysBone.targetObjects.Cast<Component>()
.Select(x => x.transform.parent)
.ZipWithNext()
.Any(x => x.Item1 != x.Item2);
if (differ)
_errorLogs.Add(ErrorLog.Validation("MergePhysBone:error:parentDiffer"));
}
var multiChildType = _sourcePhysBone.FindProperty(nameof(VRCPhysBoneBase.multiChildType));
if (multiChildType.enumValueIndex != 0 || multiChildType.hasMultipleDifferentValues)
_errorLogs.Add(ErrorLog.Validation("MergePhysBone:error:multiChildType"));
}

protected override void OptionParameter() => Void();
protected override void OptionIsAnimated() => Void();

protected override void UnsupportedPbVersion() =>
_errorLogs.Add(ErrorLog.Validation("MergePhysBone:error:unsupportedPbVersion"));

protected override void PbVersionProp(string label, string pbPropName, SerializedProperty overridePropName,
params SerializedProperty[] overrides)
=> PbProp(label, pbPropName, overridePropName, overrides);

protected override void PbProp(string label, string pbPropName, SerializedProperty overridePropName,
params SerializedProperty[] overrides) =>
PbPropImpl(label, overridePropName, overrides,
() => _sourcePhysBone.FindProperty(pbPropName).hasMultipleDifferentValues);

protected override void PbCurveProp(string label, string pbPropName, string pbCurvePropName,
SerializedProperty overridePropName,
params SerializedProperty[] overrides) =>
PbPropImpl(label, overridePropName, overrides,
() => _sourcePhysBone.FindProperty(pbPropName).hasMultipleDifferentValues
|| _sourcePhysBone.FindProperty(pbCurvePropName).hasMultipleDifferentValues);

protected override void PbPermissionProp(string label, string pbPropName, string pbFilterPropName,
SerializedProperty overridePropName,
params SerializedProperty[] overrides)
{
PbPropImpl(label, overridePropName, overrides, () =>
{
var sourceValueProp = _sourcePhysBone.FindProperty(pbPropName);
var sourceFilterProp = _sourcePhysBone.FindProperty(pbFilterPropName);
return sourceValueProp.hasMultipleDifferentValues
|| sourceValueProp.enumValueIndex == 2 && sourceFilterProp.hasMultipleDifferentValues;
});
}

protected override void Pb3DCurveProp(string label, string pbPropName, string pbXCurveLabel,
string pbXCurvePropName, string pbYCurveLabel,
string pbYCurvePropName, string pbZCurveLabel, string pbZCurvePropName, SerializedProperty overridePropName,
params SerializedProperty[] overrides) =>
PbPropImpl(label, overridePropName, overrides, () =>
_sourcePhysBone.FindProperty(pbPropName).hasMultipleDifferentValues ||
_sourcePhysBone.FindProperty(pbXCurvePropName).hasMultipleDifferentValues ||
_sourcePhysBone.FindProperty(pbYCurvePropName).hasMultipleDifferentValues ||
_sourcePhysBone.FindProperty(pbZCurvePropName).hasMultipleDifferentValues);

private void PbPropImpl(string label,
SerializedProperty overrideProp,
SerializedProperty[] overrides,
Func<bool> copy)
{
if (overrides.Any(x => x.boolValue) || overrideProp.boolValue) return;

// Copy mode
var differ = copy();

if (differ)
_differProps.Add(label);
}

protected override void ColliderProp(string label, string pbProp, SerializedProperty overrideProp)
{
if (_mergePhysBone.colliders == CollidersSettings.Copy)
{
if (_sourcePhysBone.FindProperty(pbProp).hasMultipleDifferentValues)
_errorLogs.Add(ErrorLog.Validation("MergePhysBone:error:differValue", new[] { label }));
}
}
}

}
12 changes: 12 additions & 0 deletions Editor/MergeSkinnedMeshEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using CustomLocalization4EditorExtension;
using UnityEditor;
using UnityEngine;

namespace Anatawa12.AvatarOptimizer
{
[CustomEditor(typeof(MergeSkinnedMesh))]
[InitializeOnLoad]
internal class MergeSkinnedMeshEditor : AvatarTagComponentEditorBase
{
private static class Style
Expand All @@ -24,6 +26,16 @@ private static class Style
};
}

static MergeSkinnedMeshEditor()
{
ComponentValidation.RegisterValidator<MergeSkinnedMesh>(component =>
{
if (component.GetComponent<SkinnedMeshRenderer>().sharedMesh)
return new[] { ErrorLog.Warning("MergeSkinnedMesh:warning:MeshIsNotNone") };
return null;
});
}

SerializedProperty _renderersSetProp;
SerializedProperty _staticRenderersSetProp;
SerializedProperty _removeEmptyRendererObjectProp;
Expand Down
10 changes: 8 additions & 2 deletions Editor/OptimizerProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

using System;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using UnityEditor;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDKBase.Editor.BuildPipeline;

namespace Anatawa12.AvatarOptimizer
Expand Down Expand Up @@ -49,8 +51,11 @@ private static void ProcessObject(OptimizerSession session)

private static void DoProcessObject(OptimizerSession session)
{
new Processors.UnusedBonesByReferencesToolEarlyProcessor().Process(session);
session.MarkDirtyAll();
using (BuildReport.ReportingOnAvatar(session.GetRootComponent<VRCAvatarDescriptor>()))
{
new Processors.UnusedBonesByReferencesToolEarlyProcessor().Process(session);
session.MarkDirtyAll();
}
}
}

Expand Down Expand Up @@ -83,6 +88,7 @@ public static void ProcessObject(OptimizerSession session)
{
if (_processing) return;
using (Utils.StartEditingScope(true))
using (BuildReport.ReportingOnAvatar(session.GetRootComponent<VRCAvatarDescriptor>()))
{
try
{
Expand Down
5 changes: 4 additions & 1 deletion Editor/Processors/ApplyObjectMapping.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
Expand Down Expand Up @@ -34,7 +35,9 @@ public void Apply(OptimizerSession session)
if (mapper == null)
mapper = new AnimatorControllerMapper(mapping, component.transform, session);

var mapped = mapper.MapAnimatorController(controller);
// ReSharper disable once AccessToModifiedClosure
var mapped = BuildReport.ReportingObject(controller,
() => mapper.MapAnimatorController(controller));
if (mapped != null)
p.objectReferenceValue = mapped;
}
Expand Down
3 changes: 2 additions & 1 deletion Editor/Processors/ClearEndpointPositionProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Anatawa12.AvatarOptimizer.ErrorReporting;
using UnityEditor;
using UnityEngine;
using VRC.Dynamics;
Expand All @@ -9,7 +10,7 @@ internal class ClearEndpointPositionProcessor
public void Process(OptimizerSession session)
{
foreach (var component in session.GetComponents<ClearEndpointPosition>())
Process(component.GetComponent<VRCPhysBoneBase>());
BuildReport.ReportingObject(component, () => Process(component.GetComponent<VRCPhysBoneBase>()));
}

public static void Process(VRCPhysBoneBase pb)
Expand Down
5 changes: 3 additions & 2 deletions Editor/Processors/DeleteGameObjectProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Anatawa12.AvatarOptimizer.ErrorReporting;
using UnityEngine;

namespace Anatawa12.AvatarOptimizer.Processors
Expand All @@ -6,7 +7,7 @@ internal class DeleteGameObjectProcessor
{
public void Process(OptimizerSession session)
{
foreach (var mergePhysBone in session.GetComponents<DeleteGameObject>())
BuildReport.ReportingObjects(session.GetComponents<DeleteGameObject>(), mergePhysBone =>
{
void Destroy(Object obj)
{
Expand All @@ -25,7 +26,7 @@ void Destroy(Object obj)
Destroy(component);
return true;
});
}
});
}
}
}
1 change: 1 addition & 0 deletions Editor/Processors/EditSkinnedMeshComponentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void Process(OptimizerSession session)

foreach (var processor in processors.GetSorted())
{
// TODO
processor.Process(session, target, holder);
target.AssertInvariantContract(
$"after {processor.GetType().Name} " +
Expand Down
6 changes: 4 additions & 2 deletions Editor/Processors/MakeChildrenProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using Anatawa12.AvatarOptimizer.ErrorReporting;

namespace Anatawa12.AvatarOptimizer.Processors
{
internal class MakeChildrenProcessor
{
public void Process(OptimizerSession session)
{
foreach (var makeChildren in session.GetComponents<MakeChildren>())
BuildReport.ReportingObjects(session.GetComponents<MakeChildren>(), makeChildren =>
{
foreach (var makeChildrenChild in makeChildren.children.GetAsSet())
if (makeChildrenChild)
makeChildrenChild.parent = makeChildren.transform;
}
});
}
}
}
5 changes: 3 additions & 2 deletions Editor/Processors/MergeBoneProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Assertions;
Expand All @@ -24,11 +25,11 @@ public void Process(OptimizerSession session)
// normalize map
mergeMapping.FlattenMapping();

foreach (var renderer in session.GetComponents<SkinnedMeshRenderer>())
BuildReport.ReportingObjects(session.GetComponents<SkinnedMeshRenderer>(), renderer =>
{
if (renderer.bones.Where(x => x).Any(mergeMapping.ContainsKey))
DoBoneMap(session, renderer, mergeMapping);
}
});

foreach (var pair in mergeMapping)
{
Expand Down
Loading