Skip to content

fix: dont crash on cutting with ghost paste#190

Draft
un000000 wants to merge 1 commit into
opentibiabr:mainfrom
un000000:fix_ghost_cut_crash
Draft

fix: dont crash on cutting with ghost paste#190
un000000 wants to merge 1 commit into
opentibiabr:mainfrom
un000000:fix_ghost_cut_crash

Conversation

@un000000

Copy link
Copy Markdown

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:

Make an area selection that has some items (preferably about one in-game screen or bigger)
Cut with ctrl + x.
Undo cutting with ctrl + z.
Paste clipboard with ctrl + v (this will cancel the selection). <-- this is the 'ghost paste' i'm referring to
Undo selection cancel with ctrl + z.
Cut with ctrl + x. <-- you still have 'ghost paste' on cursor, but its invisible now

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e1af782f-150d-42ce-a786-d2d36f20fff4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread source/copybuffer.cpp
Comment on lines +54 to +56
if (g_gui.secondary_map == tiles) {
g_gui.secondary_map = nullptr;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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();
	}

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.

[CRASH] Cutting while having ghost paste on cursor

1 participant