Skip to content

Commit 9b0c4c9

Browse files
author
ChengNan
committed
Fix more klockwork issues
1 parent 6d7c45d commit 9b0c4c9

11 files changed

Lines changed: 32 additions & 30 deletions

File tree

Assets/HTC.UnityPlugin/PoseTracker/Editor/PoseEaserEditor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ public override void OnInspectorGUI()
5555
layoutRect.x += layoutRect.width;
5656

5757
layoutRect.width = toggleFieldWidth;
58-
script.easePositionX = EditorGUI.ToggleLeft(layoutRect, "", script.easePositionX);
58+
if (script != null) script.easePositionX = EditorGUI.ToggleLeft(layoutRect, "", script.easePositionX);
5959
layoutRect.x += layoutRect.width;
6060

6161
layoutRect.width = toggleLabelWidth;
6262
EditorGUI.LabelField(layoutRect, "Y");
6363
layoutRect.x += layoutRect.width;
6464

6565
layoutRect.width = toggleFieldWidth;
66-
script.easePositionY = EditorGUI.ToggleLeft(layoutRect, "", script.easePositionY);
66+
if (script != null) script.easePositionY = EditorGUI.ToggleLeft(layoutRect, "", script.easePositionY);
6767
layoutRect.x += layoutRect.width;
6868

6969
layoutRect.width = toggleLabelWidth;
7070
EditorGUI.LabelField(layoutRect, "Z");
7171
layoutRect.x += layoutRect.width;
7272

7373
layoutRect.width = toggleFieldWidth;
74-
script.easePositionZ = EditorGUI.ToggleLeft(layoutRect, "", script.easePositionZ);
74+
if (script != null) script.easePositionZ = EditorGUI.ToggleLeft(layoutRect, "", script.easePositionZ);
7575
layoutRect.x += layoutRect.width;
7676

7777
// ease rotation
@@ -86,23 +86,23 @@ public override void OnInspectorGUI()
8686
layoutRect.x += layoutRect.width;
8787

8888
layoutRect.width = toggleFieldWidth;
89-
script.easeRotationX = EditorGUI.ToggleLeft(layoutRect, "", script.easeRotationX);
89+
if (script != null) script.easeRotationX = EditorGUI.ToggleLeft(layoutRect, "", script.easeRotationX);
9090
layoutRect.x += layoutRect.width;
9191

9292
layoutRect.width = toggleLabelWidth;
9393
EditorGUI.LabelField(layoutRect, "Y");
9494
layoutRect.x += layoutRect.width;
9595

9696
layoutRect.width = toggleFieldWidth;
97-
script.easeRotationY = EditorGUI.ToggleLeft(layoutRect, "", script.easeRotationY);
97+
if (script != null) script.easeRotationY = EditorGUI.ToggleLeft(layoutRect, "", script.easeRotationY);
9898
layoutRect.x += layoutRect.width;
9999

100100
layoutRect.width = toggleLabelWidth;
101101
EditorGUI.LabelField(layoutRect, "Z");
102102
layoutRect.x += layoutRect.width;
103103

104104
layoutRect.width = toggleFieldWidth;
105-
script.easeRotationZ = EditorGUI.ToggleLeft(layoutRect, "", script.easeRotationZ);
105+
if (script != null) script.easeRotationZ = EditorGUI.ToggleLeft(layoutRect, "", script.easeRotationZ);
106106
layoutRect.x += layoutRect.width;
107107

108108
if (EditorGUI.EndChangeCheck())

Assets/HTC.UnityPlugin/PoseTracker/Editor/PoseFreezerEditor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ public override void OnInspectorGUI()
5252
layoutRect.x += layoutRect.width;
5353

5454
layoutRect.width = toggleFieldWidth;
55-
script.freezePositionX = EditorGUI.ToggleLeft(layoutRect, "", script.freezePositionX);
55+
if (script != null) script.freezePositionX = EditorGUI.ToggleLeft(layoutRect, "", script.freezePositionX);
5656
layoutRect.x += layoutRect.width;
5757

5858
layoutRect.width = toggleLabelWidth;
5959
EditorGUI.LabelField(layoutRect, "Y");
6060
layoutRect.x += layoutRect.width;
6161

6262
layoutRect.width = toggleFieldWidth;
63-
script.freezePositionY = EditorGUI.ToggleLeft(layoutRect, "", script.freezePositionY);
63+
if (script != null) script.freezePositionY = EditorGUI.ToggleLeft(layoutRect, "", script.freezePositionY);
6464
layoutRect.x += layoutRect.width;
6565

6666
layoutRect.width = toggleLabelWidth;
6767
EditorGUI.LabelField(layoutRect, "Z");
6868
layoutRect.x += layoutRect.width;
6969

7070
layoutRect.width = toggleFieldWidth;
71-
script.freezePositionZ = EditorGUI.ToggleLeft(layoutRect, "", script.freezePositionZ);
71+
if (script != null) script.freezePositionZ = EditorGUI.ToggleLeft(layoutRect, "", script.freezePositionZ);
7272
layoutRect.x += layoutRect.width;
7373

7474
// freeze rotation
@@ -83,23 +83,23 @@ public override void OnInspectorGUI()
8383
layoutRect.x += layoutRect.width;
8484

8585
layoutRect.width = toggleFieldWidth;
86-
script.freezeRotationX = EditorGUI.ToggleLeft(layoutRect, "", script.freezeRotationX);
86+
if (script != null) script.freezeRotationX = EditorGUI.ToggleLeft(layoutRect, "", script.freezeRotationX);
8787
layoutRect.x += layoutRect.width;
8888

8989
layoutRect.width = toggleLabelWidth;
9090
EditorGUI.LabelField(layoutRect, "Y");
9191
layoutRect.x += layoutRect.width;
9292

9393
layoutRect.width = toggleFieldWidth;
94-
script.freezeRotationY = EditorGUI.ToggleLeft(layoutRect, "", script.freezeRotationY);
94+
if (script != null) script.freezeRotationY = EditorGUI.ToggleLeft(layoutRect, "", script.freezeRotationY);
9595
layoutRect.x += layoutRect.width;
9696

9797
layoutRect.width = toggleLabelWidth;
9898
EditorGUI.LabelField(layoutRect, "Z");
9999
layoutRect.x += layoutRect.width;
100100

101101
layoutRect.width = toggleFieldWidth;
102-
script.freezeRotationZ = EditorGUI.ToggleLeft(layoutRect, "", script.freezeRotationZ);
102+
if (script != null) script.freezeRotationZ = EditorGUI.ToggleLeft(layoutRect, "", script.freezeRotationZ);
103103
layoutRect.x += layoutRect.width;
104104

105105
if (EditorGUI.EndChangeCheck())

Assets/HTC.UnityPlugin/UPMRegistryTool/Editor/Scripts/Utils/SimpleJSON.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public static JSONNode Parse(string aJSON)
567567

568568
stack.Pop();
569569
if (Token.Length > 0 || TokenIsQuoted)
570-
ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
570+
if (ctx != null) ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
571571
TokenIsQuoted = false;
572572
TokenName = "";
573573
Token.Length = 0;
@@ -598,7 +598,7 @@ public static JSONNode Parse(string aJSON)
598598
break;
599599
}
600600
if (Token.Length > 0 || TokenIsQuoted)
601-
ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
601+
if (ctx != null) ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
602602
TokenIsQuoted = false;
603603
TokenName = "";
604604
Token.Length = 0;

Assets/HTC.UnityPlugin/Utility/Attribute/Editor/CustomOrderedEnumAttributeDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
2323
Type displayedEnumType = null;
2424
if (property.propertyType == SerializedPropertyType.Enum)
2525
{
26-
if (attr.overrideEnumType != null && attr.overrideEnumType.IsEnum)
26+
if (attr != null && attr.overrideEnumType != null && attr.overrideEnumType.IsEnum)
2727
{
2828
displayedEnumType = attr.overrideEnumType;
2929
}
@@ -34,7 +34,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3434
}
3535
else if (property.propertyType == SerializedPropertyType.Integer)
3636
{
37-
if (attr.overrideEnumType != null && attr.overrideEnumType.IsEnum)
37+
if (attr != null && attr.overrideEnumType != null && attr.overrideEnumType.IsEnum)
3838
{
3939
displayedEnumType = attr.overrideEnumType;
4040
}

Assets/HTC.UnityPlugin/Utility/Attribute/Editor/FlagsFromEnumAttributeDrawer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ private bool TryGetEnumInfo(out EnumUtils.EnumDisplayInfo info)
2727
{
2828
var ffeAttribute = attribute as FlagsFromEnumAttribute;
2929

30-
if (ffeAttribute.EnumType == null || !ffeAttribute.EnumType.IsEnum)
30+
if (ffeAttribute != null && (ffeAttribute.EnumType == null || !ffeAttribute.EnumType.IsEnum))
3131
{
3232
info = null;
3333
return false;
3434
}
3535

36-
info = EnumUtils.GetDisplayInfo(ffeAttribute.EnumType);
36+
if (ffeAttribute != null) info = EnumUtils.GetDisplayInfo(ffeAttribute.EnumType);
37+
else info = null;
38+
3739
return info != null;
3840
}
3941

Assets/HTC.UnityPlugin/Utility/Container/Editor/EnumArrayDrawer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3232
else
3333
{
3434
var target = GetTargetObjectOfProperty(property) as EnumArrayBase;
35-
EditorGUI.LabelField(position, label, new GUIContent(target.ElementType.Name + " cannot be serialized"));
35+
if (target != null) EditorGUI.LabelField(position, label, new GUIContent(target.ElementType.Name + " cannot be serialized"));
3636
}
3737
}
3838
else
3939
{
4040
var target = GetTargetObjectOfProperty(property) as EnumArrayBase;
41+
if (target == null) return;
4142
position.height = EditorGUIUtility.singleLineHeight;
4243

4344
const float btnPadding = 2f;
@@ -111,7 +112,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
111112
var target = GetTargetObjectOfProperty(property) as EnumArrayBase;
112113
for (int i = 0, imax = Mathf.Min(arrayLen, target.Length); i < imax; ++i)
113114
{
114-
if (target.IsValidIndex(i + target.MinInt))
115+
if (target != null && target.IsValidIndex(i + target.MinInt))
115116
{
116117
result += verticalSpacing + EditorGUI.GetPropertyHeight(arrayProp.GetArrayElementAtIndex(i), GUIContent.none, true);
117118
}

Assets/HTC.UnityPlugin/ViveInputUtility/Examples/2.2DDragDrop/Scripts/DragImage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void SetDraggedPosition(PointerEventData eventData)
7575
}
7676

7777
Vector3 globalMousePos;
78-
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(plane, eventData.position, eventData.pressEventCamera, out globalMousePos))
78+
if (plane != null && RectTransformUtility.ScreenPointToWorldPointInRectangle(plane, eventData.position, eventData.pressEventCamera, out globalMousePos))
7979
{
8080
rectTransform.position = globalMousePos;
8181
rectTransform.rotation = plane.rotation;

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VIUSettingsEditor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,8 @@ public static bool isRemovingFromList
427427
case StatusCode.Failure:
428428
if (!s_wasRemoved)
429429
{
430-
var request = m_removeRequest;
431-
m_removeRequest = null;
432430
Debug.LogError("Something wrong when removing package from list. error:" + m_removeRequest.Error.errorCode + "(" + m_removeRequest.Error.message + ")");
431+
m_removeRequest = null;
433432
}
434433
break;
435434
case StatusCode.Success:

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,10 @@ private static bool CheckScopeExists(List<string> scopes)
557557
{
558558
var regScopes = reg.scopes;
559559
if (regScopes == null || regScopes.Count == 0) { continue; }
560-
allScopes.AddRange(regScopes);
560+
if (allScopes != null) allScopes.AddRange(regScopes);
561561
}
562562

563-
if (allScopes.Count > 0)
563+
if (allScopes != null && allScopes.Count > 0)
564564
{
565565
foreach (var scope in scopes)
566566
{

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ViveRole/Editor/ViveRolePropertyDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
154154
roleType = ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(newRoleTypeIndex);
155155
roleTypeInfo = ViveRoleEnum.GetInfo(roleType);
156156

157-
target.SetTypeDirty();
157+
if (target != null) target.SetTypeDirty();
158158
}
159159

160160
if (newRoleValueIndex != roleValueIndex)
161161
{
162162
roleValueNameProp.stringValue = roleTypeInfo.GetNameByElementIndex(newRoleValueIndex);
163163
roleValueIntProp.intValue = roleTypeInfo.GetRoleValueByElementIndex(newRoleValueIndex);
164164

165-
target.SetValueDirty();
165+
if (target != null) target.SetValueDirty();
166166
}
167167

168168
EditorApplication.delayCall += target.Update;

0 commit comments

Comments
 (0)