mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp.git
synced 2025-10-30 08:03:03 +00:00
Fix race condition crash when setting element text, bump version to 1.2.0-rc3
This commit is contained in:
parent
7a59d7dca5
commit
4934a04d8a
3 changed files with 10 additions and 23 deletions
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
#include "../../lib/rt64/src/contrib/stb/stb_image.h"
|
||||
|
||||
const std::string version_string = "1.2.0-rc2";
|
||||
const std::string version_string = "1.2.0-rc3";
|
||||
|
||||
template<typename... Ts>
|
||||
void exit_error(const char* str, Ts ...args) {
|
||||
|
|
|
|||
|
|
@ -355,30 +355,16 @@ bool Element::is_enabled() const {
|
|||
return enabled && !disabled_from_parent;
|
||||
}
|
||||
|
||||
// Adapted from RmlUi's `EncodeRml`.
|
||||
std::string escape_rml(std::string_view string)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(string.size());
|
||||
for (char c : string)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '<': result += "<"; break;
|
||||
case '>': result += ">"; break;
|
||||
case '&': result += "&"; break;
|
||||
case '"': result += """; break;
|
||||
case '\n': result += "<br/>"; break;
|
||||
default: result += c; break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Element::set_text(std::string_view text) {
|
||||
if (can_set_text) {
|
||||
// Escape the string into Rml to prevent element injection.
|
||||
base->SetInnerRML(escape_rml(text));
|
||||
if (text_element == nullptr) {
|
||||
Rml::ElementPtr text_element_owning = get_current_context().get_document()->CreateTextNode(std::string{text});
|
||||
text_element = rmlui_static_cast<Rml::ElementText*>(text_element_owning.get());
|
||||
base->AppendChild(std::move(text_element_owning));
|
||||
}
|
||||
else {
|
||||
text_element->SetText(std::string{text});
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(false && "Attempted to set text of an element that cannot have its text set.");
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class Element : public Style, public Rml::EventListener {
|
|||
friend class ContextId; // To allow ContextId to call the handle_event method directly.
|
||||
private:
|
||||
Rml::Element *base = nullptr;
|
||||
Rml::ElementText *text_element = nullptr;
|
||||
Rml::ElementPtr base_owning = {};
|
||||
uint32_t events_enabled = 0;
|
||||
std::vector<Style *> styles;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue