steve3003 / unity-profiler-data-exporter

Utility to export data from the unity profiler
MIT License
123 stars 30 forks source link

fix for newer Unity versions #3

Closed fabolhak closed 6 years ago

fabolhak commented 6 years ago

Hello, thank you for your feedback. The changes introduced in https://github.com/steve3003/unity-profiler-data-exporter/commit/0c9f20437479283e215a513f7c371b25b55018c0 were automatically created by the Unity API Updater. However, your proposal is definitely cleaner.

I tried the second change you requested. Unfortunately, this doesn't fix the problem I initially had. With Unity 2018.1.8f1 and your suggestions I get the following errors:

NullReferenceException: Object reference not set to an instance of an object
ProfilerDataExporter.GUIClip..cctor () (at Assets/Editors/UnityWrappers/GUIClip.cs:14)
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for ProfilerDataExporter.GUIClip
ProfilerDataExporter.TableGUILayout.AddRow (ITableState tableState, Int32 rowIndex, IEnumerable`1 values) (at Assets/Editors/Utils/TableGUILayout.cs:44)
ProfilerDataExporter.ProfilerDataExporter.DrawStats () (at Assets/Editors/ProfilerDataExporter.cs:104)
ProfilerDataExporter.ProfilerDataExporter.OnGUI () (at Assets/Editors/ProfilerDataExporter.cs:71)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:291)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:284)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:251)

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Unfortunately, my C# and Unity API knowledge is too limited to understand the error.

steve3003 commented 6 years ago

Hello fabolhak, I see the issue. In Unity 2018.1.8f1 GUIClip.visibleRect is public but in 2018.2 is internal. Your solution works in both cases but I tested mine only in 2018.2. The only issue with yours is that allocates memory every time get visibleRect is called because is creating a delegate every time. I'll merge your changes and then move what you have done in a static initializer. Thanks for the help!