[Twinsen][0.16.21] I broke a fluid box (division by 0?)

This subforum contains all the issues which we already resolved.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[Twinsen][0.16.21] I broke a fluid box (division by 0?)

Post by eradicator »

While experimenting around with an assemblers fluidbox it broke in a weird way. (thread)
fluidbroke.jpg
fluidbroke.jpg (24.44 KiB) Viewed 3249 times

Code: Select all

local f = data.raw["assembling-machine"]["assembling-machine-3"].fluid_boxes

f[1]. pipe_connections = {
  { type="input-output", position = {0, -2} },
  { type="input-output", position = {0,  2} },
  }
f[1]. base_area = 1
f[1]. height = 0
f[1]. base_level = 0
I guess height=0 is causing division by 0 somewhere?
I've attached the mod and a demonstration savegame (place a pipe to make it happen) in case needed.
testmod-assembler-fluid-sharing_0.0.0.zip
(1022 Bytes) Downloaded 157 times
_autosave4.zip
(741.71 KiB) Downloaded 161 times
Twinsen
Factorio Staff
Factorio Staff
Posts: 1348
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: [Twinsen][0.16.21] I broke a fluid box (division by 0?)

Post by Twinsen »

Fluidboxes are very strangely defined. Height Influences the volume, since the volume is calculated like this:
double getVolume() const { return 100 * this->baseArea * this->height; }
When the volume is set by an assembling machine, for example, it's done like this:
void setVolume(double volume) { this->baseArea = volume / (this->height * 100); }

So you can't have a height of 0 since it will mean a fluidbox with size 0.

I updated the value checking in the next version so 0 values are not allowed.
Mimos
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Nov 07, 2016 5:15 pm
Contact:

Re: [Twinsen][0.16.21] I broke a fluid box (division by 0?)

Post by Mimos »

Twinsen wrote: double getVolume() const { return 100 * this->baseArea * this->height; }
Twinsen wrote: void setVolume(double volume) { this->baseArea = volume / (this->height * 100); }
I don't know if you use double for all liquid calculations but if you do, maybe you could increase performance a little by using float instead? On modern CPUs the speed of the Instructions should basically be the same, but maybe the reduced memory footprint could be helpful (more data can fit into the caches/be prefetched/whatever). Of course only if the precision still is sufficient, but I hope it would be ok.
Post Reply

Return to “Resolved Problems and Bugs”