Project Zomboid

Project Zomboid

Plumbing Expanded
Plumbing Leak?
I figured I'd start a thread to put my findings. Then if I find I'm totally confused about something and there is no bug you can just delete this thread =)

I just ran a new test with some of the debug logging in the mod enabled (and a few lines of my own).

In lightjaRefillFromPipedCollectors just after "--start of function execution" the sink I am testing drinking from has:

Capacity: 20
Volume: 19.985107421875 (The missing < 0.1L is the tiny amount I was referencing drinking)

Then with some of the existing debug logging that I enabled I get this (I have three collectors plumbed to this sink):

"[Lightja] collector piping 0.7078166666666666 units of (purified) tainted water"
"[Lightja] collector piping 0.7078166666666666 units of (purified) tainted water"
"[Lightja] collector piping 0.7078166666666666 units of (purified) tainted water"

So a total of ~2.1L of water is removed from the three collectors (combined) yet only 0.015L is actually required to fill the sink.
< >
Showing 1-9 of 9 comments
I also noticed that the `max_transfer_volume` being passed into `lightjaCalculateFluidTransfers` is `2.12345`, which I also noticed is a special value in the code. I suspect this is the source of the problem. Looking at my previous post, the sum of the amount removed from each of my three collectors is approximately equal to this special number, so it looks like that's being used to dictate how much is transferred rather than the available capacity of the sink.
It appears to be the overridden ISWorldObjectContextMenu.fetch that is submitting the special fetch_specific_flow_multiplier value of 2.12345 that is then being used to set the amount of fluid removed from the collectors.

I noticed this line:

if flow_multiplier == fetch_specific_flow_multiplier and sink:getModData().fluids_ui_open == true then return end

which seems to be trying to protect against this special fetch value being used by exiting early, but the "fluids_ui_open" check is false when I log it here.
Last edited by Giant Space Hamster; Feb 8 @ 4:52pm
It seems that lightjaRefillFromPipedCollectors needs a check between max_transfer_volume and the available volume of the container to prevent this leak. In this method, in the mid-420's lines (mine are off a bit b/c of added log lines) there is an if statement checking washers and dryers. I suggest this if/elseif block be modified to add one more case:

if container_name == "ComboWasherDryer" or container_name == "WashingMachine" then max_transfer_volume = capacity elseif cur_volume < (capacity / 2) then max_transfer_volume = math.max(max_transfer_volume,((capacity / 2) - cur_volume)) else -- Ensure the max transfer is not more than the available capacity max_transfer_volume = math.min(max_transfer_volume,capacity - cur_volume) end

It also might be worth doing something like this right after:

-- If less than half a unit, don't bother yet if max_transfer_volume < 0.5 then return end
Last edited by Giant Space Hamster; Feb 8 @ 5:07pm
Lightja  [developer] Feb 9 @ 4:25pm 
nice catch!

I added a new variable
local transfer_volume = math.min(capacity - cur_volume, max_transfer_volume)

and will be passing that instead of max_transfer_volume to lightjaCalculateFluidTransfers, which now has "max_transfer_volume" renamed to "transfer_volume" - i think the naming obfuscated the functionality here and thats why I didn't catch this.

Appreciate the assist! I've been busy so very nice to not have to start from scratch here.

Also, just for context, i just arbitrarily use that 2.12345 value so I know where the call is coming from, cant remember exactly why but I think it was needed to get the open sliders working on the fluid info UI.
Lightja  [developer] Feb 9 @ 4:31pm 
lol I must've at least thought about this because I have the "amount_remaining" variable defined, I just didnt actually use it!
Lightja  [developer] Feb 9 @ 4:37pm 
I'm also going to add a bunch of asserts to make sure the transfers work out as expected so people will yell at me when they see errors pop up. I think somewhere in the back of my mind i was relying on the fact that the transferfluid function handles all that, but when I filter the water I can't use that function so I need to make sure I add those checks myself.
Glad I could help! Thanks for the mod btw.
Lightja  [developer] Feb 10 @ 1:59am 
pushed a patch for this issue, version should say "Lightja 42.2.0f" in the author field of the mod info page in game.

Also added the asserts I mentioned, so if there is any other "leaking" it should show up as errors. As a result I found and fixed another edge case where stacking actions would cause that max transfer amount value to be miscalculated in cases where there are multiple collectors, somewhat of a concurrency issue.
< >
Showing 1-9 of 9 comments
Per page: 1530 50