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

This subforum contains all the issues which we already resolved.

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

Postby eradicator » Mon Feb 12, 2018 10:51 am

While experimenting around with an assemblers fluidbox it broke in a weird way. (thread)
fluidbroke.jpg
fluidbroke.jpg (24.44 KiB) Viewed 711 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 7 times

_autosave4.zip
(741.71 KiB) Downloaded 7 times
User avatar
eradicator
Smart Inserter
Smart Inserter
 
Posts: 1753
Joined: Tue Jul 12, 2016 9:03 am
Location: Mod support languages: JA/DE/EN

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

Postby Twinsen » Mon Feb 12, 2018 3:30 pm

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.
Twinsen
Factorio Staff
Factorio Staff
 
Posts: 674
Joined: Tue Sep 23, 2014 7:10 am
Location: Factorio HQ

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

Postby Mimos » Tue Feb 20, 2018 10:28 pm

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.
Mimos
Long Handed Inserter
Long Handed Inserter
 
Posts: 68
Joined: Mon Nov 07, 2016 5:15 pm


Return to Resolved Problems and Bugs

Who is online

Users browsing this forum: No registered users and 3 guests