Skip to content

Commit 5e3ad28

Browse files
common: Fix build on ryml < 0.11
1 parent 091b3a8 commit 5e3ad28

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

common/YAML.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@ std::optional<ryml::Tree> ParseYAMLFromString(ryml::csubstr yaml, ryml::csubstr
119119
#else
120120
callbacks.m_user_data = static_cast<void*>(&context);
121121
callbacks.m_error = [](const char* msg, size_t msg_len, ryml::Location location, void* user_data) {
122-
RapidYAMLContext* context = static_cast<RapidYAMLContext*>(user_data);
123-
124-
Error::SetString(context->error, std::string(msg, msg_len));
125-
std::longjmp(context->env, 1);
122+
if (RapidYAMLContext* context = static_cast<RapidYAMLContext*>(user_data))
123+
{
124+
Error::SetString(context->error, std::string(msg, msg_len));
125+
std::longjmp(context->env, 1);
126+
}
127+
else
128+
{
129+
std::string description(msg, msg_len);
130+
pxFailRel(description.c_str());
131+
}
126132
};
127133
#endif
128134

@@ -145,7 +151,11 @@ std::optional<ryml::Tree> ParseYAMLFromString(ryml::csubstr yaml, ryml::csubstr
145151

146152
// Callbacks passed to ryml::Tree are used for value parsing errors later,
147153
// so we need to clear the context before it goes out of scope.
154+
#if RYML_VERSION_MAJOR > 0 || RYML_VERSION_MINOR >= 11
148155
callbacks.set_user_data(nullptr);
156+
#else
157+
callbacks.m_user_data = nullptr;
158+
#endif
149159
tree.callbacks(callbacks);
150160

151161
return tree;

0 commit comments

Comments
 (0)