Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 04248a8

Browse files
committed
Fix for cases when structs return null (due to null declaring instance)
1 parent 3639824 commit 04248a8

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/CachedObjects/Struct/CacheColor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public override void UpdateValue()
2121
{
2222
base.UpdateValue();
2323

24+
if (Value == null) return;
25+
2426
var color = (Color)Value;
2527

2628
r = color.r.ToString();

src/CachedObjects/Struct/CacheEnum.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ namespace Explorer
1111
{
1212
public class CacheEnum : CacheObjectBase
1313
{
14-
public Type EnumType;
14+
// public Type EnumType;
1515
public string[] EnumNames;
1616

1717
public override void Init()
1818
{
19-
try
19+
if (ValueType == null && Value != null)
2020
{
21-
EnumType = Value.GetType();
22-
}
23-
catch
24-
{
25-
EnumType = (MemInfo as FieldInfo)?.FieldType ?? (MemInfo as PropertyInfo).PropertyType;
21+
ValueType = Value.GetType();
2622
}
2723

28-
if (EnumType != null)
24+
if (ValueType != null)
2925
{
30-
EnumNames = Enum.GetNames(EnumType);
26+
EnumNames = Enum.GetNames(ValueType);
3127
}
3228
else
3329
{
@@ -62,7 +58,7 @@ public void SetEnum(ref object value, int change)
6258

6359
if ((change < 0 && newindex >= 0) || (change > 0 && newindex < names.Count))
6460
{
65-
value = Enum.Parse(EnumType, names[newindex]);
61+
value = Enum.Parse(ValueType, names[newindex]);
6662
}
6763
}
6864
}

src/CachedObjects/Struct/CacheQuaternion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public override void UpdateValue()
2020
{
2121
base.UpdateValue();
2222

23+
if (Value == null) return;
24+
2325
var euler = ((Quaternion)Value).eulerAngles;
2426

2527
x = euler.x.ToString();

src/CachedObjects/Struct/CacheRect.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public override void UpdateValue()
2121
{
2222
base.UpdateValue();
2323

24+
if (Value == null) return;
25+
2426
var rect = (Rect)Value;
2527

2628
x = rect.x.ToString();

src/CachedObjects/Struct/CacheVector.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@ public class CacheVector : CacheObjectBase, IExpandHeight
2424

2525
public override void Init()
2626
{
27-
if (Value is Vector2)
27+
if (ValueType == null && Value != null)
28+
{
29+
ValueType = Value.GetType();
30+
}
31+
32+
if (ValueType == typeof(Vector2))
2833
{
2934
VectorSize = 2;
35+
m_toStringMethod = typeof(Vector2).GetMethod("ToString", new Type[0]);
3036
}
31-
else if (Value is Vector3)
37+
else if (ValueType == typeof(Vector3))
3238
{
3339
VectorSize = 3;
40+
m_toStringMethod = typeof(Vector3).GetMethod("ToString", new Type[0]);
3441
}
3542
else
3643
{
3744
VectorSize = 4;
45+
m_toStringMethod = typeof(Vector4).GetMethod("ToString", new Type[0]);
3846
}
39-
40-
m_toStringMethod = Value.GetType().GetMethod("ToString", new Type[0]);
4147
}
4248

4349
public override void UpdateValue()

0 commit comments

Comments
 (0)