forked from rosebudai/OpenRCT2-Web
Fix: Crash from use-after-free in banner text formatting during multithreaded rendering
The Banner struct had a mutable formattedTextBuffer member that was written during every call to formatTextWithColourTo(). During multithreaded rendering, multiple threads could write to this buffer simultaneously when the same banner appeared in different viewport columns, causing use-after-free. This is replaced with thread_local to give each thread its own buffer which matches the existing pattern used elsewhere in the codebase
This commit is contained in:
1 parent
13250e5536
commit
ce0969884e
3 files changed
+7
-2
No files matched your search
@@ -24,7 +24,8 @@
|
||||
- Fix: [#25854] When a guest is at 0 happiness or energy, the game draws too big of a bar in the guest stats window.
|
||||
- Fix: [#25862] Diagonal and inclined brakes are not counted when calculating upkeep cost.
|
||||
- Fix: [#25873] Repainting a banner in OpenRCT2-specific colours results in an error message.
|
||||
- Fix: [#25879] Guest window viewport doesn’t follow vehicle when they board a ride.
|
||||
- Fix: [#25879] Guest window viewport doesn’t follow vehicle when they board a ride.
|
||||
- Fix: [#25908] Crash from use-after-free in banner text formatting during multithreaded rendering.
|
||||
- Fix: [objects#419] Alignment of RCT2 red, yellow and green queue previews is off.
|
||||
- Fix: [objects#424] Jet Aeroplane decor has a hole in it.
|
||||
- Fix: [objects#425] Capacity of ‘Blob from outer space ride’ is incorrectly listed.
|
||||
|
||||
@@ -52,6 +52,11 @@ std::string Banner::getText() const
|
||||
|
||||
void Banner::formatTextWithColourTo(Formatter& ft) const
|
||||
{
|
||||
// Use thread_local buffer to avoid race conditions during multithreaded rendering.
|
||||
// Multiple threads can call this on the same Banner simultaneously when rendering
|
||||
// different viewport columns in parallel.
|
||||
thread_local std::string formattedTextBuffer;
|
||||
|
||||
auto formatToken = FormatTokenFromTextColour(textColour);
|
||||
formattedTextBuffer = FormatTokenToStringWithBraces(formatToken);
|
||||
ft.Add<StringId>(STR_STRING_STRINGID);
|
||||
|
||||
@@ -48,7 +48,6 @@ struct Banner
|
||||
OpenRCT2::ObjectEntryIndex type = kBannerNull;
|
||||
BannerFlags flags{};
|
||||
std::string text;
|
||||
mutable std::string formattedTextBuffer;
|
||||
OpenRCT2::Drawing::Colour colour{};
|
||||
RideId rideIndex{};
|
||||
OpenRCT2::Drawing::TextColour textColour{};
|
||||
|
||||
Reference in new issue
Block a user