BattletechModders / LootMagnet

BattleTech Game mod that makes salvage suck less
MIT License
11 stars 7 forks source link

NRE at BattleTech.Data.PrefabCache.PooledInstantiate #21

Closed IceRaptor closed 4 years ago

IceRaptor commented 4 years ago

From rogueticket-340-closed:

after a large battle, the spoils in the loot screen cannot be clicked or dragged, and also misarranged (some heat sink kit got mixed in partial mechs) Attachment file type: archive loot.zip 9.22 MB

i can still complete auto assign of salvage, and all spoils showed up and allocated again (a lot of stuff got hid in beginning) and properly arranged finally Suspicious Chairwoman Alekto05/20/2020 did you reload your battles?

2020-05-20T23:12:12 FYLS [ERROR] Duplicate GUID found in Reference Container: ID = commander GenNewGUID = True HadGUID = True NewObjType = BattleTech.Pilot OldObjType = BattleTech.Pilot 2020-05-20T23:12:12 FYLS [ERROR] Duplicate GUID found in Reference Container: ID = SGRef_29 GenNewGUID = True HadGUID = True NewObjType = BattleTech.Pilot OldObjType = BattleTech.Pilot 2020-05-20T23:12:12 FYLS [ERROR] Duplicate GUID found in Reference Container: ID = SGRef_2645731 GenNewGUID = True HadGUID = True NewObjType = BattleTech.MechDef OldObjType = BattleTech.MechDef whitenight05/20/2020 No Interactive Rubber Dolphin05/20/2020 Uploading Crash Report NullReferenceException at (wrapper managed-to-native) UnityEngine.GameObject.get_transform(UnityEngine.GameObject) at BattleTech.Data.PrefabCache.PooledInstantiate (System.String id, System.Nullable1[T] position, System.Nullable1[T] rotation, UnityEngine.Transform parent, System.Boolean forceInstantiate) [0x00038] in <4184af8dbeb44635831353f4d349631c>:0 at (wrapper dynamic-method) BattleTech.Data.DataManager.PooledInstantiate_Patch2(object,string,BattleTech.BattleTechResourceType,System.Nullable1<UnityEngine.Vector3>,System.Nullable1,UnityEngine.Transform) at BattleTech.UI.ListElementController_SalvageGear_NotListView.InitAndCreate (BattleTech.SalvageDef theSalvageDef, BattleTech.SimGameState theSim, BattleTech.Data.DataManager dm, BattleTech.UI.IMechLabDropTarget dropParent, System.Int32 theQuantity, System.Boolean isStoreItem) [0x00007] in <4184af8dbeb44635831353f4d349631c>:0 at BattleTech.UI.AAR_SalvageScreen.AddNewSalvageEntryToWidget (BattleTech.SalvageDef salvageDef, BattleTech.UI.IMechLabDropTarget targetWidget) [0x000d2] in <4184af8dbeb44635831353f4d349631c>:0 at LootMagnet.Helper.CalculateAndAddAvailableSalvage (BattleTech.UI.AAR_SalvageScreen salvageScreen, System.Collections.Generic.List1[T] potentialSalvage) [0x00051] in <ce33c4a3e79144009a2e7f7e50e8db54>:0 at LootMagnet.AAR_SalvageScreen_CalculateAndAddAvailableSalvage.Prefix (BattleTech.UI.AAR_SalvageScreen __instance, BattleTech.Contract ___contract, System.Int32& loot magnet is probably the victim here, error is in vanilla code Interactive Rubber Dolphin05/20/2020 @FrostRaptor I know it's technically not your code erroring, but any ideas? FrostRaptor05/20/2020 What's patching BattleTech.Data.DataManager.PooledInstantiate? That error comes from: GameObject gameObject = this.dataManager.PooledInstantiate(ListElementController_BASE_NotListView.INVENTORY_ELEMENT_PREFAB_NotListView, BattleTechResourceType.UIModulePrefabs, null, null, null); So it's trying to load the UIModulePrefab for a static list... which should be fine... Interactive Rubber Dolphin05/20/2020 io.mission.modreputation so CAC what fails is not the patch though, I don't think? FrostRaptor05/20/2020 Nope, I was just trying to understand what's failing. That pooledInstantiate line should be the same for every 'line-item' in the display, if I'm reading this properly. So I don't know why it would fail for one line, and not the other. CustomLocalization is it's own thing, right? Because my first thought was maybe a localization error, but doesn't look like that would be the case if it's CAC and not CL Interactive Rubber Dolphin05/20/2020 Yeah, localization is it's own thing hmm Suspicious_Tinn05/25/2020 !close KMiSSioNToday at 2:49 PM well BattleTech.Data.PrefabCache.PooledInstantiate (System.String id, System.Nullable1[T] position, System.Nullable`1[T] rotation, UnityEngine.Transform parent, System.Boolean forceInstantiate) [0x00038]

it is go.transform.SetParent((Transform) null); looks like someone put game object to pool - than destroy it @FrostRaptor FrostRaptorToday at 9:03 PM Hurm... I just checked LootMagnet code, and I'm not invoking PooledInstantiate for any logic within my code. Though... I wonder if this could cause it. Gnivler offered this code to LM, and it has a destroy in it. public class FadeText : MonoBehaviour { private static float fadeSpeed = 0.6f; private TextMeshProUGUI text;

    void Awake() {

        text = gameObject.GetComponentInChildren<TextMeshProUGUI>(true);
        StartCoroutine(FadeOutText());

        IEnumerator FadeOutText() {
            text.color = new Color(text.color.r, text.color.g, text.color.b, 1);
            while (text.color.a > 0)
            {
                text.color = new Color(
                    text.color.r, text.color.g, text.color.b, text.color.a - Time.deltaTime * fadeSpeed);
                yield return null;
            }

            Destroy(gameObject);
        }
    }
}

Yeah... and he's destroying the object after selling it. Inside of a InventoryItemElement_NotListView postfix, he's doing:

Object.Destroy(__instance.gameObject); Which is probably what's causing this. I bet this is a second or third battle, where the user sold an item in a preceeding battle. The UI element would be destroyed,but the pool thinks it's present. Because gnivler's code destroyed it.

IceRaptor commented 4 years ago

Should be fixed in 5.4.0