Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent crash in condition light division #3053

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ void ConditionLight::addCondition(std::shared_ptr<Creature> creature, const std:
const auto &conditionLight = condition->static_self_cast<ConditionLight>();
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 @@ -2558,9 +2558,13 @@ 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) {
g_logger().warn("[ConditionLight::setParam] Trying to set invalid light value: '{}', defaulting to 1.", value);
}
lightInfo.level = std::max<uint8_t>(1, static_cast<uint8_t>(value));
return true;
}

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

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