fix: dont crash on cutting with ghost paste#190
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Code Review
This pull request updates the CopyBuffer::clear method to safely delete tiles and prevent dangling pointers by clearing g_gui.secondary_map. The reviewer recommended calling g_gui.EndPasting() instead of manually setting the pointer to nullptr to ensure the internal pasting state is correctly reset, which addresses a potential visual bug.
| if (g_gui.secondary_map == tiles) { | ||
| g_gui.secondary_map = nullptr; | ||
| } |
There was a problem hiding this comment.
Instead of manually setting secondary_map to nullptr, you should call g_gui.EndPasting(). This will not only clear the secondary_map pointer but also reset the pasting flag to false. This fixes the "visual bug" mentioned in the PR description where the ghost paste remains active (but invisible) and allows for accidental pasting after the buffer has been cleared.
if (g_gui.secondary_map == tiles) {
g_gui.EndPasting();
}


Fixes #123
This pr fixes crash at the tradeoff of introducing new visual (mostly harmless) bug: When cutting with ghost paste (explained below) hovering on cursor, the ghost paste actually stays, but is invisible. Left clicking will paste that invisible content.
Steps to reproduce this visual bug are same as for crash: