Prevent occasional clipboard crash - #1054
Merged
Merged
Conversation
Co-authored-by: SadPencil <11227602+SadPencil@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix clipboard operation crash in listbox
Wrap ClipboardService.SetText calls in try-catch to prevent clipboard crash
Aug 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent the client from crashing when clipboard copy operations fail (e.g., clipboard locked by another process) by guarding map name copy actions in the multiplayer game lobby UI.
Changes:
- Replaced inline clipboard-copy lambdas in the map context menu with dedicated private methods.
- Wrapped clipboard copy operations in
try/catch (Exception)and show a non-fatalXNAMessageBoxon failure.
Suppressed comments (1)
DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs:892
- CopyOriginalMapNameToClipboard() shows the same error text / localization key as CopyMapNameToClipboard(), so users selecting “Copy Original Name” will see an incorrect message (“map name”). Use a distinct string/key for the original-name action.
catch (Exception)
{
XNAMessageBox.Show(WindowManager, "Error".L10N("Client:Main:Error"), "Unable to copy map name to clipboard.".L10N("Client:Main:ClipboardCopyMapNameFailed"));
}
Comment on lines
317
to
321
| mapContextMenu.AddItem("Copy Map Name".L10N("Client:Main:CopyMapName"), | ||
| selectAction: () => ClipboardService.SetText(Map?.Name)); | ||
| selectAction: CopyMapNameToClipboard); | ||
| mapContextMenu.AddItem("Copy Original Name".L10N("Client:Main:CopyOriginalMapName"), | ||
| selectAction: () => ClipboardService.SetText(Map?.UntranslatedName), | ||
| selectAction: CopyOriginalMapNameToClipboard, | ||
| visibilityChecker: () => Map?.UntranslatedName != Map?.Name); |
Member
|
Since this crash cannot be easily reproduced (but it exists), and the modification is small enough, I will merge it without testing the client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ClipboardService.SetText(from TextCopy) can throw if the clipboard is locked by another process. Any unguarded call site crashes the client. All client-owned call sites are now protected; XNAUI submodule calls cannot be modified.What Changed
GameLobbyBase.cs— extracted the two bareClipboardService.SetTextlambdas (Copy Map Name / Copy Original Name context menu actions) into dedicated private methodsCopyMapNameToClipboard()andCopyOriginalMapNameToClipboard(), each wrapped intry/catch (Exception)with a user-facingXNAMessageBoxerror dialog on failureGlobalContextMenu.cs—CopyLink()was already protected; no change neededXNATextBoxCtrl+X/C/V,XNAListBoxCtrl+C) remains unguarded — out of scope for this repoTest Result without Your PR Applied
Pressing Ctrl+C on a listbox item or selecting "Copy Map Name" from the map context menu while the clipboard is locked by another process throws an unhandled exception and crashes the client.
Test Result with Your PR Applied
The same operations catch the exception and display a non-fatal error dialog instead of crashing.
Breaking Changes
Documentation
Checklist