Fix reagent temperature mismatch crash (#23063)

* Please describe the intent of your changes in a clear fashion.
This PR addresses a crash (`SERVER-PROD-2R6`) caused by a temperature
mismatch when adding new reagents, particularly in low-volume metabolism
holders.

The root cause was identified as a combination of:
1. A coarse rounding guard in `set_thermal_energy` that discarded
small-but-valid thermal energy changes.
2. A temperature assertion in `add_reagent` that was too sensitive to
floating-point inaccuracies.
3. The `nicotine` reagent lacking an explicit `fallback_specific_heat`.

Changes implemented:
- **`code/modules/reagents/Chemistry-Temperature.dm`**: Modified
`set_thermal_energy` to remove the `round(delta, 1)` guard. Now,
`if(!delta)` is used, allowing small, non-zero energy changes to be
processed.
- **`code/modules/reagents/Chemistry-Holder.dm`**: Updated the
temperature assertion in `add_reagent` from `round(temperature, 1) !=
round(get_temperature(), 1)` to `abs(temperature - get_temperature()) >
0.1`. This provides a more robust, tolerance-based comparison.
-
**`code/modules/reagents/Chemistry-Reagents/Chemistry-Reagents-Medicine.dm`**:
Added `fallback_specific_heat = 1.67` to
`/singleton/reagent/mental/nicotine` to ensure it has a proper specific
heat value.

* 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-2R6](https://aurorastation.sentry.io/issues/7661064998/?seerDrawer=true)

---------

Co-authored-by: VMSolidus <evilexecutive@gmail.com>
This commit is contained in:
sentry[bot]
2026-08-19 18:09:57 +00:00
committed by GitHub
co-authored by VMSolidus
parent 0a16ab6564
commit 81c4eb2b79
4 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -135,7 +135,7 @@
newreagent.set_thermal_energy(new_thermal_energy, src, safety = TRUE)
else
newreagent.set_temperature(temperature, src, safety = TRUE)
if(!new_thermal_energy && round(temperature, 1) != round(get_temperature(), 1))
if(!new_thermal_energy && abs(temperature - get_temperature()) > 0.1)
crash_with("Temperature [temperature] did not match [get_temperature()] after adding NEW reagent [rtype]!")
else // Existing reagent
var/old_energy = (newreagent.get_thermal_energy(src)/reagent_volumes[rtype]) * amount
@@ -1280,6 +1280,7 @@
goodmessage = list("You feel good.","You feel relaxed.","You feel alert and focused.")
value = 2
alchohol_affected = FALSE
fallback_specific_heat = 1.67 // Approximate specific heat of liquid nicotine (J/g·K)
/singleton/reagent/mental/nicotine/overdose(var/mob/living/carbon/M, var/alien, var/removed, var/scale, var/datum/reagents/holder)
..()
@@ -13,7 +13,7 @@
/singleton/reagent/proc/set_thermal_energy(amount, var/datum/reagents/holder, safety = FALSE)
var/delta = amount / get_thermal_fraction(holder) - holder.thermal_energy
if(!round(delta, 1))
if(!delta)
return
holder.add_thermal_energy(delta, safety) // this handles on_heat_change for us