acdamiani / schema

Visual intelligence for the Unity game engine
https://schema-ai.com
MIT License
53 stars 4 forks source link

I get this error when searching for components. #2

Closed irfanderdiyok closed 10 months ago

irfanderdiyok commented 11 months ago

unity 2021.3.21f1 editor

IndexOutOfRangeException: Index was outside the bounds of the array. QuickSearch.Search (System.String needle, System.String haystack) (at Assets/Schema/Editor/Window/QuickSearch.cs:342) QuickSearch.SearchThroughResults (System.Collections.Generic.IEnumerable1[T] types, System.String query) (at Assets/Schema/Editor/Window/QuickSearch.cs:322) QuickSearch.<CorrectSelection>b__31_0 () (at Assets/Schema/Editor/Window/QuickSearch.cs:298) Schema.Utilities.CacheDictionary2[T1,T2].GetOrCreate (T1 key, System.Func`1[TResult] default) (at Assets/Schema/Utilities/CacheDictionary.cs:13) QuickSearch.CorrectSelection (System.Int32 selected) (at Assets/Schema/Editor/Window/QuickSearch.cs:298) QuickSearch.Focus () (at Assets/Schema/Editor/Window/QuickSearch.cs:286) QuickSearch.OnGUI (System.Int32 id) (at Assets/Schema/Editor/Window/QuickSearch.cs:65) UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) (at :0) UnityEditor.EditorWindow:EndWindows() SchemaEditor.Internal.ComponentSystem.Components.WindowComponent:OnGUI() (at Assets/Schema/Editor/Canvas/Components/WindowComponent.cs:61) SchemaEditor.Internal.ComponentCanvas:Draw() (at Assets/Schema/Editor/Canvas/ComponentCanvas.cs:265) SchemaEditor.NodeEditor:OnGUI() (at Assets/Schema/Editor/Window/NodeEditorGUI.cs:45) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

acdamiani commented 11 months ago

Thanks, I'll look into this.

acdamiani commented 10 months ago

I'm having trouble reproducing this issue. Can you provide the following:

ILLNOISE143 commented 10 months ago
private static int Search(string needle, string haystack)
{
    int[] T = Preprocess(needle);
    int skip = 0;

    while (haystack.Length - skip >= needle.Length)
    {
        if (Same(haystack.Substring(skip), needle, needle.Length))
            return skip;

        // skip = skip + T[haystack[skip + needle.Length]];
        skip += 1;
    }

    return -1;
}

Hi Changed Search to this in QuickSearch.cs and this worked for me :)

irfanderdiyok commented 10 months ago

Thank You @ILLNOISE143

acdamiani commented 10 months ago

Just committed a fix for this. My guess is that this issue was caused by non-ASCII search characters. I was trying to do something clever here and use a more efficient search algorithm, but it looks like it's too issue-prone to be worth it. I've just changed it to a String.IndexOf instead.