OpenTTD icon indicating copy to clipboard operation
OpenTTD copied to clipboard

Fix #12914: Fix use of invalidated pointer in viewport drawer.

Open PeterN opened this issue 6 months ago • 0 comments

Motivation / Problem

As per #12914, use of invalid dangling pointer due to vector reallocation in viewport drawer.

Description

~~Store destination list and index within the list, instead of a direct pointer, to find child index to update.~~

Use index of last child instead of pointer to update next_child element.

In case there is no child sprite yet, the most recent parent sprite's first_child is updated instead.

Limitations

I haven't been able to prove that child sprites are only even added to the most recent parent sprite.

Switching to std::deque is probably less intrusive but not sure about iteration performance.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

PeterN avatar Aug 23 '24 20:08 PeterN