neon-age / Smart-Inspector

Fluent re-take on Unity Inspector UX. Packed with QoL improvements.
MIT License
923 stars 52 forks source link

New update seems to have caused issues on Linux 2021.1.9f1 editor. Crashes and closes editor right away. #8

Open MostHated opened 3 years ago

MostHated commented 3 years ago

Hey there, I created a test project a few weeks ago, whenever this was first released, it was using 2021.1.7f1 at the time and I pulled the new changes into the project and went to start it up, but as soon as the editor first loads after the initial Unity splash/loading image, the editor simply closes, or gives a bug report window. I removed the asset from my assets folder and started Unity again to be sure and it loaded just fine. I put the Smart-Inspector folder back in the project and as it was importing/compiling it just locked up. I forced the project closed, tried to open again, and once again it crashed. The below is an excerpt from the tail end of the logs, though, it doesn't seem too helpful, unfortunately.

---- Edit, I added another bit from a log that looks like it has some more info that is relevant to the patcher, not sure if it is related, but it came up just before it locked up again.

Tail end of logs ```sh Unloading 308 unused Assets to reduce memory usage. Loaded Objects now: 4304. Total: 4.445728 ms (FindLiveObjects: 0.162896 ms CreateObjectMapping: 0.088576 ms MarkObjects: 3.713755 ms DeleteObjects: 0.479810 ms) ProgressiveSceneManager::Cancel() [MODES] ModeService[none].Initialize [MODES] ModeService[none].LoadModes [MODES] Loading mode Default (0) for mode-current-id-Test_Project [LAYOUT] About to load Library/CurrentLayout-default.dwlt, keepMainWindow=False Unhandled description string [ Unhandled description string ] Unhandled description string \ [MODES] ModeService[default].InitializeCurrentMode [MODES] ModeService[default].RaiseModeChanged(default, default) [MODES] ModeService[default].UpdateModeMenus Unhandled description string [ Unhandled description string ] Unhandled description string \ IsTimeToCheckForNewEditor: Update time 1624411204 current 1624408549 [Project] Loading completed in 11.095 seconds Project init time: 0.273 seconds Template init time: 0.000 seconds Package Manager init time: 0.000 seconds Asset Database init time: 0.000 seconds Global illumination init time: 0.000 seconds Assemblies load time: 0.000 seconds Unity extensions init time: 0.000 seconds Asset Database refresh time: 0.000 seconds Scene opening time: 2.838 seconds Unhandled description string [ Unhandled description string ] Unhandled description string \ Unhandled description string [ Unhandled description string ] Unhandled description string \ Caught fatal signal - signo:11 code:128 errno:0 addr:(nil) Obtained 12 stack frames. #0 0x007f630425cbb0 in funlockfile #1 0x007f63040d27d9 in psiginfo #2 0x007f6304185d3b in __printf_chk #3 0x007f61241c7e56 in mono_breakpoint_clean_code #4 0x00000041977308 in (Unknown) #5 0x00000040f43dac in System.InvalidCastException:.ctor () #6 0x007f61240d5be5 in mono_print_method_from_ip #7 0x007f61242459fc in mono_perfcounter_foreach #8 0x007f61242491c1 in mono_object_unbox #9 0x007f6124202c2b in mono_exception_from_token #10 0x007f61241c73ac in mono_breakpoint_clean_code #11 0x00000041978fa3 in (Unknown) Launching bug reporter QObject: Cannot create children for a parent that is in a different thread. (Parent is QObject(0x1ebc4c0), parent's thread is QThread(0x1557630), current thread is Thread(0x18016d0) ```
Additional Logs ```sh 41359000-41369000 rwxp 00000000 00:00 0 41bd2000-41be2000 rwxp 00000000 00:00 0 55e3bdf17000-55e3bfce0000 r--p 00000000 103:05 6704642 /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity 55e3bfce0000-55e3c316a000 r-xp 01dc9000 103:05 6704642 /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity 55e3c316a000-55e3c3270000 r--p 05253000 103:05 6704642 /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity 55e3c3270000-55e3c32bc000 rw-p 05359000 103:05 6704642 /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity 55e3c32bc000-55e3c3560000 rw-p 00000000 00:00 0 55e3c4c5f000-55e3cec26000 rw-p 00000000 00:00 0 [heap] 7f167487f000-7f167ac49000 r--p 00000000 103:05 6704584 /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity_s.debug 7f1680000000-7f1680108000 rw-p 00000000 00:00 0 7f1680108000-7f1684000000 ---p 00000000 00:00 0 7f16875ff000-7f1687600000 ---p 00000000 00:00 0 7f1687600000-7f1687e00000 rw-p 00000000 00:00 0 7f1688000000-7f1688021000 rw-p 00000000 00:00 0 7f1688021000-7f168c000000 ---p 00000000 00:00 0 7f168c000000-7f168c02a000 rw-p 00000000 00:00 0 7f168c02a000-7f1690000000 ---p 00000000 00:00 0 7f1690000000-7f1690021000 rw-p 00000000 00:00 0 # ------ A while lot more of the above - cut because it was hundreds/ possibly thousands of lines # ----------------------------------------------------------------------------------------------- Native stacktrace: /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Data/MonoBleedingEdge/MonoEmbedRuntime/libmonobdwgc-2.0.so(+0xd809c) [0x7f175415309c] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Data/MonoBleedingEdge/MonoEmbedRuntime/libmonobdwgc-2.0.so(+0x5be3f) [0x7f17540d6e3f] /lib/x86_64-linux-gnu/libpthread.so.0(+0x14bb0) [0x7f195db52bb0] /lib/x86_64-linux-gnu/libpthread.so.0(pthread_mutex_lock+0x4) [0x7f195db49824] /lib/x86_64-linux-gnu/libnvidia-glcore.so.465.31(+0xda98a9) [0x7f1822e518a9] /lib/x86_64-linux-gnu/libGLX_nvidia.so.0(+0x7a267) [0x7f184452b267] /lib/x86_64-linux-gnu/libc.so.6(+0x91f30) [0x7f195d9e5f30] /lib/x86_64-linux-gnu/libc.so.6(__libc_fork+0x24) [0x7f195da32924] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x384061d) [0x55e3c175761d] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x383f335) [0x55e3c1756335] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x2ac1794) [0x55e3c09d8794] /lib/x86_64-linux-gnu/libpthread.so.0(+0x14bb0) [0x7f195db52bb0] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x24af9d8) [0x55e3c03c69d8] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x2deb6c4) [0x55e3c0d026c4] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x2deb5c1) [0x55e3c0d025c1] /home/mosthated/Unity/Hub/Editor/2021.1.9f1/Editor/Unity(+0x4965b94) [0x55e3c287cb94] /lib/x86_64-linux-gnu/libpthread.so.0(+0x9590) [0x7f195db47590] /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7f195da6d223] Debug info from gdb: mono_gdb_render_native_backtraces not supported on this platform, unable to find gdb or lldb Obtained 9 stack frames. #0 0x0055e3c08b7773 in profiling::Profiler::InitializeUserThread(char const*, char const*) #1 0x0055e3c0a017a3 in profiling::gc_finalizer_start(void*) #2 0x007f1754257482 in mono_profiler_set_iomap_report_callback #3 0x007f175428f9a4 in mono_callspec_cleanup #4 0x007f1754260cea in mono_threads_set_shutting_down #5 0x007f17542c2d1b in GC_inner_start_routine #6 0x007f17542b7851 in GC_call_with_stack_base #7 0x007f195db47590 in start_thread #8 0x007f195da6d223 in clone Launching bug reporter ```

Thanks, -MH ------------------------------------

neon-age commented 3 years ago

So it always crashes the Editor on launch now? Was it not happening in previous versions? I remember getting one occasional crash that was somehow related to ActiveEditorTracker, but couldn't get it now - it causes freezes without crash or log

neon-age commented 3 years ago

Wait what? It dies on "Patcher.GUISkinHasLoaded()"?

MostHated commented 3 years ago

It looks like it, everything else before that point is pretty typical Unity stuff. This is from just above the Patcher lines from the log. I can try closing and reopening a few more times to see if I see anything different.

Application.AssetDatabase Initial Script Refresh End
Application.AssetDatabase.Refresh Start
Refresh completed in 0.250891 seconds.
RefreshInfo: RefreshV2(ForceSynchronousImport) scanfilter:
RefreshProfiler: Total: 249.835ms
Application.AssetDatabase.Refresh End
RefreshInfo: StopAssetImportingV2(ForceSynchronousImport) scanfilter:
RefreshProfiler: Total: 1.802ms
Refresh completed in 0.258507 seconds.
RefreshInfo: RefreshV2(NoUpdateAssetOptions) scanfilter:
RefreshProfiler: Total: 257.750ms
Launched and connected shader compiler UnityShaderCompiler after 0.01 seconds
Initializing Unity extensions:
Refresh completed in 0.155609 seconds.
RefreshInfo: RefreshV2(NoUpdateAssetOptions) scanfilter:
RefreshProfiler: Total: 154.427ms
UpdateMenuTitleForLanguage: 10
Unloading 273 Unused Serialized files (Serialized files now loaded: 0)
System memory in use before: 113.9 MB.
System memory in use after: 113.4 MB.

Unloading 308 unused Assets to reduce memory usage. Loaded Objects now: 4282.
Total: 4.346984 ms (FindLiveObjects: 0.150812 ms CreateObjectMapping: 0.087814 ms MarkObjects: 3.629738 ms  DeleteObjects: 0.478066 ms)

ProgressiveSceneManager::Cancel()
[MODES] ModeService[none].Initialize
[MODES] ModeService[none].LoadModes
[MODES] Loading mode Default (0) for mode-current-id-Test_Project
[LAYOUT] About to load Library/CurrentLayout-default.dwlt, keepMainWindow=False
Unhandled description string [
Unhandled description string ]
Unhandled description string \
[MODES] ModeService[default].InitializeCurrentMode
[MODES] ModeService[default].RaiseModeChanged(default, default)
[MODES] ModeService[default].UpdateModeMenus
Unhandled description string [
Unhandled description string ]
Unhandled description string \
IsTimeToCheckForNewEditor: Update time 1624411204 current 1624409192
[Project] Loading completed in 16.321 seconds
    Project init time:              0.151 seconds
        Template init time:         0.000 seconds
        Package Manager init time:      0.000 seconds
        Asset Database init time:       0.000 seconds
        Global illumination init time:  0.000 seconds
        Assemblies load time:           0.000 seconds
        Unity extensions init time:     0.000 seconds
        Asset Database refresh time:    0.000 seconds
    Scene opening time:             1.641 seconds
Unhandled description string [
Unhandled description string ]
Unhandled description string \
Unhandled description string [
Unhandled description string ]
Unhandled description string \

NullReferenceException: Object reference not set to an instance of an object
  at AV.Inspector.Patcher.GUISkinHasLoaded () [0x0000d] in /mnt/x/_unity/_test/Test_Project/Assets/Smart-Inspector/Patches/Provider/Patcher.cs:41
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs) (at /home/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnhandledExceptionHandler.bindings.cs:46)

(Filename: Assets/Smart-Inspector/Patches/Provider/Patcher.cs Line: 41)
neon-age commented 3 years ago

Can you try to comment out line 32 and 33 in Patcher.Init?

MostHated commented 3 years ago

Sure, one sec, I will give it a try.

MostHated commented 3 years ago

Unfortunately, that didn't help. Just to see, I commented out the [InitializeOnLoadMethod] of the Patcher init and it loaded just fine, but then I realized that, that method is probably what handles everything this asset is about, lol.

neon-age commented 3 years ago

You need to comment out the lines related to GUISkin check, not the whole Init :)

MostHated commented 3 years ago

Yeah, I did. I tried commenting 32 and 33 first, but it didn't seem to make a difference. It still closed right away when loading the editor.

neon-age commented 3 years ago

But what error it gives in this case? Couldn't be 41 line now

neon-age commented 3 years ago

I'd need to try to check this issue later on my Manjaro

MostHated commented 3 years ago

This was unfortunately all it gave this last time.

Caught fatal signal - signo:11 code:1 errno:0 addr:0xf893b11
Obtained 2 stack frames.
#0  0x007fc6821a6bb0 in funlockfile
#1  0x00000041f976a7 in (Unknown)
Launching bug reporter
Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created.
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QObject(0x10029e0), parent's thread is QThread(0xd163d0), current thread is Thread(0xfbee70)
MostHated commented 3 years ago

Looking at how this initializes, I will see if I can remove one of the patches at a time to see which one then allows it to load.

neon-age commented 3 years ago

Yes, it should be related to one of the patches being injected / initialized at a wrong time, as was with #5

MostHated commented 3 years ago

Ok, I changed to the following and I found what looks like the one:


        static void GetPatches()
        {
            if (patches != null) 
                return;
            patches = new List<PatchBase>();

            var patchTypes = TypeCache.GetTypesDerivedFrom(typeof(PatchBase));
            for (var i = 0; i < patchTypes.Count; i++)
            {

                if (i == 5) // Skipping: PropertyEditorPatch - Editor loaded when it skipped this one
                {
                    Debug.Log($"Skipping: {patchTypes[i].Name}");
                    continue;
                }

                var type = patchTypes[i];
                if (type.IsAbstract)
                    continue;

                var instance = Activator.CreateInstance(type) as PatchBase;
                patches.Add(instance);
            }
        }
neon-age commented 3 years ago

Hooh, we're getting somewhere! What if you comment out OnEnable and OnDisable patches in PropertyEditorPatch? These methods are likely to be called during Editor launch

MostHated commented 3 years ago

I removed the skip, then made this adjustment, but it crashed as it had before.


        protected override IEnumerable<Patch> GetPatches()
        {
            // var onEnable = AccessTools.Method(PropertyEditorRef.type, "OnEnable");
            // var onDisable = AccessTools.Method(PropertyEditorRef.type, "OnDisable");

            var rebuildContent = AccessTools.Method(PropertyEditorRef.type, "RebuildContentsContainers");
            var endRebuildContent = AccessTools.Method(PropertyEditorRef.type, "EndRebuildContentContainers");

            // yield return new Patch(onEnable, postfix: nameof(OnEnable_));
            // yield return new Patch(onDisable, nameof(_OnDisable));

            yield return new Patch(rebuildContent, nameof(_RebuildContentsContainers), nameof(RebuildContentsContainers_));
            #if UNITY_2020_1_OR_NEWER
            yield return new Patch(endRebuildContent, postfix: nameof(EndRebuildContentContainers_));
            #endif
        }
neon-age commented 3 years ago

But it doesn't crash if the rest of these patches / Patch itself is skipped?

MostHated commented 3 years ago

If PropertyEditorPatch is skipped from loading via the method I used prior, the editor loads. If I set everything back to normal, but then in PropertyEditorPatch, I make the changes above, it crashes. Did I comment out the proper parts you were referring to?

neon-age commented 3 years ago

Yes, but wait. It crashes even when Editor is already launched?

MostHated commented 3 years ago

I am not sure, when I made the changes, I closed the editor and reopened it, and it crashed.

MostHated commented 3 years ago

When I launch the project with these changes, it crashes.

neon-age commented 3 years ago

I understand, but could you try to launch skipping PropertyEditorPatch and then comment it back in?

MostHated commented 3 years ago

Should I keep OnEnable and OnDisable commented out, or reenable them first?

neon-age commented 3 years ago

You can just skip the whole patch with yield break;

MostHated commented 3 years ago

Ok, like this?


    internal class PropertyEditorPatch : PatchBase
    {
        protected override IEnumerable<Patch> GetPatches()
        {
            yield break;
            var onEnable = AccessTools.Method(PropertyEditorRef.type, "OnEnable");
            var onDisable = AccessTools.Method(PropertyEditorRef.type, "OnDisable");

            var rebuildContent = AccessTools.Method(PropertyEditorRef.type, "RebuildContentsContainers");
            var endRebuildContent = AccessTools.Method(PropertyEditorRef.type, "EndRebuildContentContainers");

            yield return new Patch(onEnable, postfix: nameof(OnEnable_));
            yield return new Patch(onDisable, nameof(_OnDisable));

            yield return new Patch(rebuildContent, nameof(_RebuildContentsContainers), nameof(RebuildContentsContainers_));
            #if UNITY_2020_1_OR_NEWER
            yield return new Patch(endRebuildContent, postfix: nameof(EndRebuildContentContainers_));
            #endif
        }
MostHated commented 3 years ago

Ok, so with that patch skipped, the editor open, you then want me to remove the skip but keep the yield break; and then recompile?

neon-age commented 3 years ago

No, once it's launched, you need to get patch back in by removing yield break; Btw, using break; makes skipping in GetPatches() for loop redundant

MostHated commented 3 years ago

Ok, so, I removed the skip, removed the yield, and recompiled and it crashed.

neon-age commented 3 years ago

So it cuts down the problem to SmartInspector.OnRebuildContent(). Could you try to comment out RebuildToolbar line? ActiveEditorTracker is used the most in there

MostHated commented 3 years ago

I dont see anything with the name of RebuildToolbar within PropertyEditorPatch?

--- Edit, oh, sorry, did you mean

        void RebuildToolbar()
        {
            toolbar?.Rebuild(this);
        }

in Base/SmartInspector?

neon-age commented 3 years ago

Only what's inside SmartInspector.OnRebuildContent, yes

MostHated commented 3 years ago

I did this, but it crashed:

        /// <see cref="PropertyEditorPatch.RebuildContentsContainers_"/>
        internal void OnRebuildContent(RebuildStage stage)
        {
            RebuildingInspector = this;
            FirstInitOnInspectorIfNeeded();

            //Debug.Log(stage);

            if (stage == RebuildStage.BeforeEditorElements)
            {
                editors.Clear();
                RemoveUserElements();
            }

            if (stage == RebuildStage.BeforeRepaint)
            {
                // RebuildToolbar();
            }

            if (stage == RebuildStage.AfterRepaint)
            {
                // TODO: Fix one-frame issue when dragged element keeps expanded layout of element that was last there
            }
        }
neon-age commented 3 years ago

Okay I guess then it also might be caused by SmartInspector.Inject method, or the rest of the OnRebuildContent

Or 71 line PropertyEditorRef.GetTracker(propertyEditor) in SmartInspector constructor! (most likely)

MostHated commented 3 years ago

Hmm.... I just tried


        internal SmartInspector(EditorWindow propertyEditor)
        {
            this.propertyEditor = propertyEditor;
            // this.tracker = PropertyEditorRef.GetTracker(propertyEditor);
        }

But it still crashed. :(

neon-age commented 3 years ago

That doesn't seem right.. Nothing else could be called by PropertyEditorPatch

Could you both comment out tracker and skip Inject method? And if it doesn't work, the rest of the OnRebuildContent

MostHated commented 3 years ago

Like this?


        internal SmartInspector(EditorWindow propertyEditor)
        {
            this.propertyEditor = propertyEditor;
            // this.tracker = PropertyEditorRef.GetTracker(propertyEditor);
        }

        internal void OnEnable() {}
        internal void OnDisable() {}

        internal void Inject()
        {
            // var result = TryInject();
            //Debug.Log(result);
        }
MostHated commented 3 years ago

Still crashed

neon-age commented 3 years ago

Okaay... Then I have another assumption - EditorElementPatch.CreateEditorElement causes it.

PropertyEditorPatch.Rebuild creates SmartInspector instance and makes it a RebuildingInspector Then EditorElementPatch creates and setups the element for it, right after vanilla Init, but one of it's used methods causes the crash

Try to comment out line 51 and 52 in EditorElementPatch.Init_

MostHated commented 3 years ago

oi, this is not making it easy, is it? lol.

I did the following, but still crashed


        static void Init_(VisualElement __instance, IMGUIContainer ___m_Header, IMGUIContainer ___m_Footer, EditorWindow ___inspectorWindow)
        {
            var smartInspector = SmartInspector.RebuildingInspector;

            // var data = CreateEditorElement(__instance, ___m_Header, ___m_Footer, smartInspector);
            // smartInspector.SetupEditorElement(data);
        }
neon-age commented 3 years ago

That ain't right.. Other suspects are still commented out?

I can't think of any other method that can be called during rebuild

MostHated commented 3 years ago

Oh, no, I was uncommenting things as we went along so that only the current one asked was commented.

neon-age commented 3 years ago

oi, this is not making it easy, is it? lol.

This is made that way because vanilla EditorElement.Init is always called inside PropertyEditor.RebuildContentsContainers

Oh, no, I was uncommenting things as we went along so that only the current one asked was commented.

We need to find the last commented out suspect that fixes the crash :)

JuDelCo commented 3 years ago

Happens to me as well (PopOS 20.10, Unity 2021.1.12f1)

neon-age commented 3 years ago

v0.8.0-pre.1 got a Patches UI. It should now be easier to debug this issue.

image

Here's a config with plugin and patches disabled - Smart Inspector Prefs.zip It needs to be inside project's Library folder, can be modified before Editor launch.

MostHated commented 3 years ago

Ok, nice. I will give it a go and see how it turns out. :+1:

MostHated commented 3 years ago

Ok, nice. Adding the prefs to library was able to let me load up the editor. (Side note, this issue page for some reason is lagging my browser terribly. Each letter I type takes 1 second to appear. I have never had that happen on github before, and it is only this particular issue thread. Something I pasted into here before must be lagging it out.)

Edit - even more strange, it seems to only happen on new posts. I hit edit on this post and now its fine again, so nevermind, must be one of my browser extensions.

Anyways, it looks like having my settings like this, which I believe is the same as when I manually disabled the one patch via script, the edit loads up fine.

neon-age commented 3 years ago

What if you disable all other patches but enable PropertyEditorPatch?

MostHated commented 3 years ago

Doing that made it so the editor will no longer start.