SpikeHimself / XPortal

XPortal is a Valheim mod that lets you select a portal's destination from a list. XPortal is a complete rewrite of AnyPortal.
GNU General Public License v3.0
19 stars 6 forks source link

More farming issues now with Plant Easily bricked by Xportal #54

Closed Astral-Crescent closed 1 year ago

Astral-Crescent commented 1 year ago

I am mentally handicapped and cannot fill out your form the way you want.

Please listen to me, anyway.

Copy-Pasted from my bug report on Plant Easily now that I know it is Xportal's fault.

"Since the recent update, When I try to mass harvest it only harvests 1 node but yields Many crops, causing unfair duplications, and then the multiple crops are all replanted ontop of each other, leaving them unable to grow, and it consumes no seeds, and remains as a fully ripe crop.

edit: This is being triggered by another mod called XPortal, for... some reason. If you can sus out why that might be, I would appreciate it. "

When I attempt to do the above with the mod Plant Easily, I get an infinite readout of errors to do with Xportal.

To replicate: Install Plant Easily by Advize, enable mass harvest and replant when harvested (not sure if needed, but these are the features I was bug testing when I noticed this error with Xportal), attempt to mass harvest or harvest crops.

AdvizeGH commented 1 year ago

The above steps are unnecessary, simply place more than 1 piece at a time with PlantEasily (which happens to happen during auto crop replanting as mentioned by the OP) and watch your console light up. I would imagine this happens with similar mods (MassFarming, Farming) as well but haven't confirmed.

[Error  : Unity Log] ArgumentException: An item with the same key has already been added. Key: System.Action`1[System.Boolean]
Stack trace:
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <695d1cc93cca45069c528c15c9fdd749>:0)
XPortal.QueuedAction.Queue (System.Action`1[T] action, System.Int32 delay) (at <f92d2cd1b1fe4c0888553264fc479679>:0)
XPortal.Patches.Piece_SetCreator.CheckWearNTearCreationTime (System.Boolean delayed) (at <f92d2cd1b1fe4c0888553264fc479679>:0)
XPortal.Patches.Piece_SetCreator.Postfix (Piece __instance) (at <f92d2cd1b1fe4c0888553264fc479679>:0)
(wrapper dynamic-method) Piece.DMD<Piece::SetCreator>(Piece,long)
Advize_PlantEasily.PlantEasily.PlacePiece (Player player, UnityEngine.GameObject go, Piece piece) (at <acc17140760a4befab1818747c5facd7>:0)
Advize_PlantEasily.PlantEasily+PlayerPlacePiece.Postfix (Player __instance, Piece piece) (at <acc17140760a4befab1818747c5facd7>:0)
(wrapper dynamic-method) Player.DMD<Player::PlacePiece>(Player,Piece)
Player.UpdatePlacement (System.Boolean takeInput, System.Single dt) (at <2959d3c128e64c61a08dcc9bb6744ec3>:0)
Player.Update () (at <2959d3c128e64c61a08dcc9bb6744ec3>:0)

Followed by the always repeating, even while game is paused or after quitting to title screen:

[Error  : Unity Log] NullReferenceException: Object reference not set to an instance of an object
Stack trace:
XPortal.Patches.Piece_SetCreator.CheckWearNTearCreationTime (System.Boolean delayed) (at <f92d2cd1b1fe4c0888553264fc479679>:0)
XPortal.QueuedAction.Trigger () (at <f92d2cd1b1fe4c0888553264fc479679>:0)
XPortal.QueuedAction.Update () (at <f92d2cd1b1fe4c0888553264fc479679>:0)
XPortal.XPortal.Update () (at <f92d2cd1b1fe4c0888553264fc479679>:0)

I would also add that these pieces do not have wear & tear components.

Edit: Issue occurs even when placing a single piece with the cultivator while PlantEasily is installed, even when PlantEasily's features are disabled via its config (causing all of its patches to return before any code is executed).

AdvizeGH commented 1 year ago

Judging by the comments in your code, you're clearly doing some strange things to work around some niche issues. Despite this, here's a couple things I noticed that are suspect to me.

XPortal.Patches.Piece.CheckWearNTearCreationTime(bool) is seemingly never called with a false argument for the delayed parameter (unless I missed it elsewhere), does it not always queue itself to be run again without ever reaching the latter portion of the method?

Your Piece.SetCreator Postfix patch doesn't check if m_WearNTear is null or not, nor is it checked anywhere else that it's referenced. I would suggest at least 1 initial null check before proceeding with your other code.

m_WearNTear = __instance.GetComponent<WearNTear>();
if (m_WearNTear) CheckWearNTearCreationTime();
SpikeHimself commented 1 year ago

Judging by the comments in your code, you're clearly doing some strange things to work around some niche issues

That is correct @AdvizeGH, please see here for reference as to why:

https://github.com/SpikeHimself/XPortal/issues/36#issuecomment-1493277277

https://github.com/BepInEx/HarmonyX/issues/71

I will look at this issue as soon as I have time.

AdvizeGH commented 1 year ago

That was a really interesting read. This issue recently cropped up elsewhere but it was assumed to be limited to Transpilers.

I can't think of a workaround that I could offer except to explore alternative entry points... perhaps TeleportWorld.Awake() or somewhere in there.

SpikeHimself commented 1 year ago

Hi @Astral-Crescent, thank you very much for reporting this issue.

I have just released v1.2.12 which fixes this problem.