Skip to content

Commit

Permalink
AGS: Engine: fixed ScriptOverlay loosing ID when changing text
Browse files Browse the repository at this point in the history
From upstream acd7ac23d35aafbceb0115b3c3ae1a946e4de20a
  • Loading branch information
tag2015 authored and criezy committed Jan 20, 2023
1 parent 5dea74f commit 6f82ba6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion engines/ags/engine/ac/global_overlay.cpp
Expand Up @@ -57,7 +57,8 @@ int CreateTextOverlay(int xx, int yy, int wii, int fontid, int text_color, const
void SetTextOverlay(int ovrid, int xx, int yy, int wii, int fontid, int text_color, const char *text) {
RemoveOverlay(ovrid);
const int disp_type = ovrid;
if (CreateTextOverlay(xx, yy, wii, fontid, text_color, text, disp_type) != ovrid)
int new_ovrid = CreateTextOverlay(xx, yy, wii, fontid, text_color, text, disp_type);
if (new_ovrid != ovrid)
quit("SetTextOverlay internal error: inconsistent type ids");
}

Expand Down
11 changes: 9 additions & 2 deletions engines/ags/engine/ac/overlay.cpp
Expand Up @@ -60,11 +60,18 @@ void Overlay_SetText(ScriptOverlay *scover, int wii, int fontid, int text_color,
int xx = game_to_data_coord(_GP(screenover)[ovri].x);
int yy = game_to_data_coord(_GP(screenover)[ovri].y);

RemoveOverlay(scover->overlayId);
// FIXME: a refactor needed!
// these calls to RemoveOverlay and CreateOverlay below are potentially dangerous,
// because they may allocate new script objects too under certain conditions.
// This did not happen because users only had access to custom overlay pointers before,
// but now they also may access internal overlays (such as Say text and portrait).
const int disp_type = scover->overlayId;
RemoveOverlay(scover->overlayId);

if (CreateTextOverlay(xx, yy, wii, fontid, text_color, get_translation(text), disp_type) != scover->overlayId)
int new_ovrid = CreateTextOverlay(xx, yy, wii, fontid, text_color, get_translation(text), disp_type);
if (new_ovrid != disp_type)
quit("SetTextOverlay internal error: inconsistent type ids");
scover->overlayId = new_ovrid;
}

int Overlay_GetX(ScriptOverlay *scover) {
Expand Down

0 comments on commit 6f82ba6

Please sign in to comment.