Fix crash which could occur when adding/updating text effects
When DParam 0 or 1 contained a leftover string See: #612
This commit is contained in:
@@ -620,8 +620,7 @@ void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
|
|||||||
cost = -cost;
|
cost = -cost;
|
||||||
msg = STR_INCOME_FLOAT_INCOME;
|
msg = STR_INCOME_FLOAT_INCOME;
|
||||||
}
|
}
|
||||||
SetDParam(0, cost);
|
AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING, cost);
|
||||||
AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -638,17 +637,15 @@ void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income
|
|||||||
|
|
||||||
Point pt = RemapCoords(x, y, z);
|
Point pt = RemapCoords(x, y, z);
|
||||||
|
|
||||||
SetDParam(0, transfer);
|
|
||||||
if (income == 0) {
|
if (income == 0) {
|
||||||
AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
|
AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING, transfer);
|
||||||
} else {
|
} else {
|
||||||
StringID msg = STR_FEEDER_COST;
|
StringID msg = STR_FEEDER_COST;
|
||||||
if (income < 0) {
|
if (income < 0) {
|
||||||
income = -income;
|
income = -income;
|
||||||
msg = STR_FEEDER_INCOME;
|
msg = STR_FEEDER_INCOME;
|
||||||
}
|
}
|
||||||
SetDParam(1, income);
|
AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING, transfer, income);
|
||||||
AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,8 +664,7 @@ TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID str
|
|||||||
|
|
||||||
assert(string != STR_NULL);
|
assert(string != STR_NULL);
|
||||||
|
|
||||||
SetDParam(0, percent);
|
return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC, percent);
|
||||||
return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,8 +676,7 @@ void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID string)
|
|||||||
{
|
{
|
||||||
assert(string != STR_NULL);
|
assert(string != STR_NULL);
|
||||||
|
|
||||||
SetDParam(0, percent);
|
UpdateTextEffect(te_id, string, percent);
|
||||||
UpdateTextEffect(te_id, string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -42,7 +42,7 @@ struct TextEffect : public ViewportSign {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Text Effects */
|
/* Text Effects */
|
||||||
TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
|
TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode, uint64 param1, uint64 param2)
|
||||||
{
|
{
|
||||||
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
||||||
|
|
||||||
@@ -59,26 +59,30 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, Text
|
|||||||
/* Start defining this object */
|
/* Start defining this object */
|
||||||
te.string_id = msg;
|
te.string_id = msg;
|
||||||
te.duration = duration;
|
te.duration = duration;
|
||||||
te.params_1 = GetDParam(0);
|
te.params_1 = param1;
|
||||||
te.params_2 = GetDParam(1);
|
te.params_2 = param2;
|
||||||
te.mode = mode;
|
te.mode = mode;
|
||||||
|
|
||||||
/* Make sure we only dirty the new area */
|
/* Make sure we only dirty the new area */
|
||||||
te.width_normal = 0;
|
te.width_normal = 0;
|
||||||
|
SetDParam(0, param1);
|
||||||
|
SetDParam(1, param2);
|
||||||
te.UpdatePosition(ZOOM_LVL_OUT_8X, center, y, msg);
|
te.UpdatePosition(ZOOM_LVL_OUT_8X, center, y, msg);
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
void UpdateTextEffect(TextEffectID te_id, StringID msg, uint64 param1, uint64 param2)
|
||||||
{
|
{
|
||||||
/* Update details */
|
/* Update details */
|
||||||
TextEffect *te = _text_effects.data() + te_id;
|
TextEffect *te = _text_effects.data() + te_id;
|
||||||
if (msg == te->string_id && GetDParam(0) == te->params_1) return;
|
if (msg == te->string_id && param1 == te->params_1) return;
|
||||||
te->string_id = msg;
|
te->string_id = msg;
|
||||||
te->params_1 = GetDParam(0);
|
te->params_1 = param1;
|
||||||
te->params_2 = GetDParam(1);
|
te->params_2 = param2;
|
||||||
|
|
||||||
|
SetDParam(0, param1);
|
||||||
|
SetDParam(1, param2);
|
||||||
te->UpdatePosition(ZOOM_LVL_OUT_8X, te->center, te->top, te->string_id, te->string_id - 1);
|
te->UpdatePosition(ZOOM_LVL_OUT_8X, te->center, te->top, te->string_id, te->string_id - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,10 +29,10 @@ using TextEffectID = uint16_t;
|
|||||||
static const TextEffectID INVALID_TE_ID = UINT16_MAX;
|
static const TextEffectID INVALID_TE_ID = UINT16_MAX;
|
||||||
|
|
||||||
void MoveAllTextEffects(uint delta_ms);
|
void MoveAllTextEffects(uint delta_ms);
|
||||||
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8 duration, TextEffectMode mode);
|
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8 duration, TextEffectMode mode, uint64 param1 = 0, uint64 param2 = 0);
|
||||||
void InitTextEffects();
|
void InitTextEffects();
|
||||||
void DrawTextEffects(ViewportDrawerDynamic *vdd, DrawPixelInfo *dpi, bool load_transparent);
|
void DrawTextEffects(ViewportDrawerDynamic *vdd, DrawPixelInfo *dpi, bool load_transparent);
|
||||||
void UpdateTextEffect(TextEffectID effect_id, StringID msg);
|
void UpdateTextEffect(TextEffectID effect_id, StringID msg, uint64 param1 = 0, uint64 param2 = 0);
|
||||||
void RemoveTextEffect(TextEffectID effect_id);
|
void RemoveTextEffect(TextEffectID effect_id);
|
||||||
void UpdateAllTextEffectVirtCoords();
|
void UpdateAllTextEffectVirtCoords();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user