pyanodon / pybugreports

Central bug-report repository for pymods
The Unlicense
5 stars 1 forks source link

Crash with Multiblade "fish" turbine #440

Closed ChaosSaber closed 4 months ago

ChaosSaber commented 4 months ago

Mod source

Factorio Mod Portal

Which mod are you having an issue with?

Operating system

GNU/Linux

What kind of issue is this?

What is the problem?

Crash when using the Multiblade "fish" turbine. Crash report:

The mod Pyanodons Alternative Energy (1.2.20) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event pyalternativeenergy::on_nth_tick(61)
__pyalternativeenergy__/scripts/wind/wind.lua:94: attempt to concatenate local 'direction' (a nil value)
stack traceback:
    __pyalternativeenergy__/scripts/wind/wind.lua:94: in function 'draw_windmill'
    __pyalternativeenergy__/scripts/wind/wind.lua:144: in function <__pyalternativeenergy__/scripts/wind/wind.lua:129>

Cause: When surface.wind_orientation is exactly 0.9375, wind_dir will be 0. Since lua starts counting indices from 1, wind_dir_names[0] gives nil, resulting in the quoted error. To fix the issue:

--- scripts/wind/wind.lua       2024-02-28 07:26:46.000000000 +0100
+++ scripts/wind/wind.lua.fixed 2024-03-05 18:22:06.557758826 +0100
@@ -108,7 +108,7 @@
 }

 function Wind.calculate_wind_direction(surface)
-    local wind_dir = math.ceil((surface.wind_orientation + 1/16) % 1 * 8)
+    local wind_dir = 1 + math.floor((surface.wind_orientation + 1/16) * 8 % 8)
     return wind_dir_names[wind_dir]
 end

Disclaimer: I did not find or solved this problem. I'm posting this for a work colleague who has neither github nor discord. Here is the link to his forum post: https://forums.factorio.com/viewtopic.php?p=604905#p604905

Steps to reproduce

No response

Additional context

No response

Log file

No response

notnotmelon commented 4 months ago

Thank you. However the proposed solution is incorrect. It fails on 0.875.

Fixed here: https://github.com/pyanodon/pyalternativeenergy/commit/ac6eeb4af81d8f53bf85fc88706d151e0a4b381b