Skip to content

Commit

Permalink
Fix condition light crash (#4806)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekiro authored Oct 8, 2024
1 parent 624e888 commit 293e3eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ void ConditionLight::addCondition(Creature* creature, const Condition* condition
const ConditionLight& conditionLight = static_cast<const ConditionLight&>(*condition);
lightInfo.level = conditionLight.lightInfo.level;
lightInfo.color = conditionLight.lightInfo.color;
lightChangeInterval = ticks / lightInfo.level;
lightChangeInterval = ticks / std::max<uint8_t>(1, lightInfo.level);
internalLightTicks = 0;
creature->setCreatureLight(lightInfo);
g_game.changeLight(creature);
Expand All @@ -1794,9 +1794,14 @@ bool ConditionLight::setParam(ConditionParam_t param, int32_t value)
}

switch (param) {
case CONDITION_PARAM_LIGHT_LEVEL:
lightInfo.level = value;
case CONDITION_PARAM_LIGHT_LEVEL: {
if (value < 1) {
std::cout << "[ConditionLight::setParam] trying to set invalid light value: " << value
<< " defaulting to 1" << std::endl;
}
lightInfo.level = std::max(1, value);
return true;
}

case CONDITION_PARAM_LIGHT_COLOR:
lightInfo.color = value;
Expand Down
2 changes: 1 addition & 1 deletion src/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class ConditionLight final : public Condition
bool unserializeProp(ConditionAttr_t attr, PropStream& propStream) override;

private:
LightInfo lightInfo;
LightInfo lightInfo{1};
uint32_t internalLightTicks = 0;
uint32_t lightChangeInterval = 0;
};
Expand Down

0 comments on commit 293e3eb

Please sign in to comment.