Skip to content

Commit

Permalink
Merge pull request #1947 from zivmaor/find-references-crash-fix
Browse files Browse the repository at this point in the history
Find references crash fix
  • Loading branch information
Miepee authored Dec 1, 2024
2 parents 0ca898a + 54968e3 commit b8587ce
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace UndertaleModTool.Windows
/// </summary>
public partial class FindReferencesTypesDialog : Window
{
private static readonly MainWindow mainWindow = Application.Current.MainWindow as MainWindow;

private readonly UndertaleResource sourceObj;
private readonly UndertaleData data;
private readonly bool dontShowWindow = false;
Expand Down Expand Up @@ -140,9 +142,21 @@ private async void SearchButton_Click(object sender, RoutedEventArgs e)
return;
}

var results = UndertaleResourceReferenceMethodsMap.GetReferencesOfObject(sourceObj, data, typesList);
FindReferencesResults dialog = new(sourceObj, data, results);
dialog.Show();
FindReferencesResults dialog = null;
try
{
var results = UndertaleResourceReferenceMethodsMap.GetReferencesOfObject(sourceObj, data, typesList);
dialog = new(sourceObj, data, results);
dialog.Show();
}
catch (Exception ex)
{
mainWindow.ShowError("An error occured in the object references related window.\n" +
$"Please report this on GitHub.\n\n{ex}");
dialog?.Close();

}

}
else
{
Expand Down Expand Up @@ -173,9 +187,19 @@ private async void SearchButton_Click(object sender, RoutedEventArgs e)
}

Hide();
var results = await UndertaleResourceReferenceMethodsMap.GetUnreferencedObjects(data, typesDict);
FindReferencesResults dialog = new(data, results);
dialog.Show();
FindReferencesResults dialog = null;
try
{
var results = await UndertaleResourceReferenceMethodsMap.GetUnreferencedObjects(data, typesDict);
dialog = new(data, results);
dialog.Show();
}
catch (Exception ex)
{
mainWindow.ShowError("An error occured in the object references related window.\n" +
$"Please report this on GitHub.\n\n{ex}");
dialog?.Close();
}
}

Close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public static class UndertaleResourceReferenceMap
(typeof(UndertaleGameObject), "Game objects"),
(typeof(UndertaleGeneralInfo), "General info"),
(typeof(UndertaleOptions.Constant), "Game options constants"),
(typeof(UndertaleLanguage), "Languages"),
(typeof(UndertalePath), "Paths"),
(typeof(UndertaleRoom), "Rooms"),
(typeof(UndertaleScript), "Scripts"),
Expand All @@ -179,6 +178,15 @@ public static class UndertaleResourceReferenceMap
}
},
new TypesForVersion
{
// Bytecode version 16
Version = (16, uint.MaxValue, uint.MaxValue),
Types = new[]
{
(typeof(UndertaleLanguage), "Languages"),
}
},
new TypesForVersion
{
Version = (2, 0, 0),
Types = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,6 @@ IEnumerable<object[]> GetExtnFunctions()
outDict["Game options constants"] = new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) };
}

if (types.Contains(typeof(UndertaleLanguage)))
{
bool langsMatches = data.Language.EntryIDs.Contains(obj)
|| data.Language.Languages.Any(x => x.Name == obj || x.Region == obj
|| x.Entries.Contains(obj));
if (langsMatches)
outDict["Languages"] = new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) };
}

if (types.Contains(typeof(UndertalePath)))
{
var paths = data.Paths.Where(x => x.Name == obj);
Expand Down Expand Up @@ -632,6 +623,28 @@ IEnumerable<object[]> GetExtnFunctions()
}
},
new PredicateForVersion()
{
// Bytecode version 16
Version = (16, uint.MaxValue, uint.MaxValue),
Predicate = (objSrc, types, checkOne) =>
{
if (!types.Contains(typeof(UndertaleLanguage)))
return null;

if (objSrc is not UndertaleString obj)
return null;

bool langsMatches = data.Language.EntryIDs.Contains(obj)
|| data.Language.Languages.Any(x => x.Name == obj || x.Region == obj
|| x.Entries.Contains(obj));

if (langsMatches)
return new() { { "Languages", new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) } } };
else
return null;
}
},
new PredicateForVersion()
{
Version = (2, 0, 0),
Predicate = (objSrc, types, checkOne) =>
Expand Down Expand Up @@ -1566,23 +1579,17 @@ await Task.Run(() =>
}
}
}

await mainWindow.StopProgressBarUpdater();
mainWindow.HideProgressBar();
}
catch
finally
{
await mainWindow.StopProgressBarUpdater();
mainWindow.HideProgressBar();

mainWindow.IsEnabled = true;
stringReferences = null;
funcReferences = null;
variReferences = null;

throw;
}
mainWindow.IsEnabled = true;
stringReferences = null;
funcReferences = null;
variReferences = null;

if (outDict.Count == 0)
return null;
Expand Down

0 comments on commit b8587ce

Please sign in to comment.