InvalidCastException: Specified cast is not valid.
stepsani opened this issue · 1 comments
stepsani commented
Hi, I'm trying to export data from the Memory profiler and I run into this issue.
InvalidCastException: Specified cast is not valid.
ProfilerDataExporter.SplitterState..ctor (System.Single[] relativeSizes, System.Int32[] minSizes, System.Int32[] maxSizes) (at Assets/Editor/UnityWrappers/SplitterState.cs:31)
ProfilerDataExporter.FunctionTableState..ctor (ProfilerDataExporter.ProfilerColumn[] columnsToShow, System.Collections.Generic.Dictionary`2[TKey,TValue] columnHeaders, System.String sortHeader) (at Assets/Editor/FunctionTableState.cs:34)
ProfilerDataExporter.ProfilerDataExporter.DrawStats () (at Assets/Editor/ProfilerDataExporter.cs:150)
ProfilerDataExporter.ProfilerDataExporter.OnGUI () (at Assets/Editor/ProfilerDataExporter.cs:114)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <786b546700bc48b68852821de5e46ca9>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <786b546700bc48b68852821de5e46ca9>:0)
UnityEditor.DockArea.OldOnGUI () (at <786b546700bc48b68852821de5e46ca9>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <c735460d95a241ccbea413909634f410>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
Any help?
Thanks!
dcastares commented
Hi there, I was having the same issue with Unity 2022.3.10f1, and fixed it by adding some validations before returning values in UnityWrappers\SplitterState.cs, this are the methods I've modified:
SplitterState.cs Ln25:
public SplitterState(float[] relativeSizes, int[] minSizes, int[] maxSizes)
{
splitter = SplitterStateType.InvokeMember(null,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.CreateInstance, null, null, new object[] { relativeSizes, minSizes, maxSizes });
realSizes = Array.ConvertAll((float[])RealSizesInfo.GetValue(splitter), x => (int)x);
}
SplitterState.cs Ln68:
public int splitSize
{
get
{
var splitSize = SplitterStateType.InvokeMember("splitSize",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetField, null, splitter, null);
return splitSize is int intValue ? intValue : 0;
}
}
@steve3003 would be amazing to add it on the next version if you are updating it any time soon.