Dispose ItemContextClass created in InspectWindowUpdateStatsOnSwapPatch to prevent stack overflow from BSG's buggy implementation
This commit is contained in:
@@ -35,6 +35,7 @@ namespace UIFixes
|
|||||||
public static void Enable()
|
public static void Enable()
|
||||||
{
|
{
|
||||||
new DetectSwapSourceContainerPatch().Enable();
|
new DetectSwapSourceContainerPatch().Enable();
|
||||||
|
new CleanupSwapSourceContainerPatch().Enable();
|
||||||
new GridViewCanAcceptSwapPatch().Enable();
|
new GridViewCanAcceptSwapPatch().Enable();
|
||||||
new DetectGridHighlightPrecheckPatch().Enable();
|
new DetectGridHighlightPrecheckPatch().Enable();
|
||||||
new DetectSlotHighlightPrecheckPatch().Enable();
|
new DetectSlotHighlightPrecheckPatch().Enable();
|
||||||
@@ -150,6 +151,20 @@ namespace UIFixes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CleanupSwapSourceContainerPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(typeof(ItemView), nameof(ItemView.OnEndDrag));
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPrefix]
|
||||||
|
public static void Prefix(ItemView __instance)
|
||||||
|
{
|
||||||
|
SourceContainer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class GridViewCanAcceptSwapPatch : ModulePatch
|
public class GridViewCanAcceptSwapPatch : ModulePatch
|
||||||
{
|
{
|
||||||
protected override MethodBase GetTargetMethod()
|
protected override MethodBase GetTargetMethod()
|
||||||
@@ -468,13 +483,20 @@ namespace UIFixes
|
|||||||
[PatchPostfix]
|
[PatchPostfix]
|
||||||
public static void Postfix(DraggedItemView __instance, ItemContextAbstractClass itemUnderCursor)
|
public static void Postfix(DraggedItemView __instance, ItemContextAbstractClass itemUnderCursor)
|
||||||
{
|
{
|
||||||
|
if (itemUnderCursor?.Item == __instance.Item)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (SourceContainer is Component sourceComponent)
|
if (SourceContainer is Component sourceComponent)
|
||||||
{
|
{
|
||||||
ItemSpecificationPanel panel = sourceComponent.GetComponentInParent<ItemSpecificationPanel>();
|
ItemSpecificationPanel panel = sourceComponent.GetComponentInParent<ItemSpecificationPanel>();
|
||||||
if (panel != null)
|
if (panel != null)
|
||||||
{
|
{
|
||||||
Slot slot = new R.SlotItemAddress(__instance.ItemAddress).Slot;
|
Slot slot = new R.SlotItemAddress(__instance.ItemAddress).Slot;
|
||||||
ItemContextClass itemUnderCursorContext = itemUnderCursor != null ? new ItemContextClass(itemUnderCursor, ItemRotation.Horizontal) : null;
|
|
||||||
|
// ItemContextClass must be disposed after using, or its buggy implementation causes an infinite loop / stack overflow
|
||||||
|
using ItemContextClass itemUnderCursorContext = itemUnderCursor != null ? new ItemContextClass(itemUnderCursor, ItemRotation.Horizontal) : null;
|
||||||
panel.method_15(slot, itemUnderCursorContext);
|
panel.method_15(slot, itemUnderCursorContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user