Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RmlUI Context handling improvements #1761

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ChrisFloofyKitsune
Copy link
Member

context handling improvements

  • manage contexts in the "contexts_to_remove" hashset more carefully to prevent use-after-free crash.
  • Remove context from removal hashset if it is "recreated" in the same frame.

use ranges::rotate to reorder clicked context

* manage contexts in the "contexts_to_remove" hashset more carefully to prevent use-after-free crash.
* Remove context from removal hashset if it is "recreated" in the same frame.
Rml::Context* context = Rml::GetContext(name);
if (context == nullptr) {
context = Rml::CreateContext(name, {0, 0});
} else if (state->contexts_to_remove.contains(context)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (state->contexts_to_remove.contains(context)) {
} else if (state->contexts_to_remove.contains(context)) {
// can happen if name reused on the same frame

if (context == nullptr) {
context = Rml::CreateContext(name, {0, 0});
} else if (state->contexts_to_remove.contains(context)) {
state->contexts_to_remove.erase(context);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do without the .contains check? .erase has to search for the element anyway so we'd avoid searching it twice if present and won't see any difference if not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize I could do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants