Hydroponics: Fix invalid plant icon state from negative growth (#22523)

* Please describe the intent of your changes in a clear fashion.
This PR addresses a server crash caused by an invalid icon state being
requested for certain plants, specifically those with spreading traits
like biomass vines.

**Root Cause:**
The `refresh_icon()` proc for `/obj/effect/plant` was directly
decrementing the instance variable `max_growth` based on fringe
conditions (`spread_distance` and `at_fringe`). This meant that
`max_growth` could become negative over multiple processing ticks. When
`seed.get_icon()` was subsequently called with a negative growth stage
(e.g., -2), it constructed an invalid icon state string (e.g.,
`biomass--2`), leading to a crash.

**Solution:**
To prevent `max_growth` from being permanently altered, a local variable
`effective_max` is now used within `refresh_icon()`. This local variable
is initialized with the current `max_growth` and then decremented based
on the fringe conditions. The `growth` calculation and subsequent icon
state generation now use `effective_max`, ensuring that the persistent
`max_growth` variable remains stable and positive, thus preventing the
generation of invalid negative icon states.

* Please make sure that, in the case of mapping changes, you include
images of these changes in the PR's description.
* Please make sure to mark your PR as wip or review required by making a
comment with !wip or !review required
* If you include sprites/sounds/... (assets) that you have not created
yourself specify the license and original author below.
* Ensure that you also credit them in the appropriate location /
changelog as specified in the contributor guidelines

### Asset Licenses
The following assets that **have not** been created by myself are
included in this PR:

| Path | Original Author | License |
| --- | --- | --- |
| icons/example.dmi | ExamplePerson (Example Station) | CC0 |


Fixes SERVER-PROD-TJ

---------

Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
This commit is contained in:
sentry[bot]
2026-06-01 10:36:40 +00:00
committed by GitHub
co-authored by sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> VMSolidus
parent a1723313df
commit 124f7ee17b
2 changed files with 12 additions and 6 deletions
@@ -188,15 +188,17 @@
SHOULD_NOT_SLEEP(TRUE)
overlays.Cut()
var/growth = 0
if(growth_threshold)
growth = min(max_growth, round(health/growth_threshold))
var/effective_max = max_growth
var/at_fringe = get_dist(src,parent)
if(spread_distance > 5)
if(at_fringe >= (spread_distance-3))
max_growth--
effective_max--
if(at_fringe >= (spread_distance-2))
max_growth--
effective_max--
var/growth = 0
if(growth_threshold)
growth = min(effective_max, round(health/growth_threshold))
var/image/our_icon = seed.get_icon(growth)
@@ -205,7 +207,7 @@
AddOverlays(our_icon)
if(growth>2 && growth == max_growth)
if(growth>2 && growth == effective_max)
layer = (seed && seed.force_layer) ? seed.force_layer : 5
if(growth_type in list(GROWTH_VINES,GROWTH_BIOMASS))
opacity = 1