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