Open
Harden COM port enumeration to avoid Bluetooth-driven startup/dropdown crashes#3740
Conversation
Copilot
AI
changed the title
[WIP] Fix crash in Mission Planner when scanning Bluetooth COM ports
Harden COM port enumeration to avoid Bluetooth-driven startup/dropdown crashes
Jun 12, 2026
meee1
marked this pull request as ready for review
July 2, 2026 06:29
meee1
force-pushed
the
copilot/fix-mission-planner-crash-bluetooth-com-ports
branch
from
July 2, 2026 06:29
23f48cb to
e9cb1ae
Compare
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Mission Planner startup/UI crashes and hangs caused by problematic serial/Bluetooth drivers during COM port enumeration by adding a timeout-protected enumeration path with a Windows registry fallback, plus additional guarding when populating the serial-port dropdown.
Changes:
- Added a timeout-based COM port enumeration path with Windows registry fallback (
HARDWARE\DEVICEMAP\SERIALCOMM) inMissionPlanner.Comms.SerialPort.GetPortNames(). - Wrapped serial-port dropdown population in
MainV2.PopulateSerialportList()with exception handling to keep the UI responsive. - Updated logging to include more contextual error messages (but some new messages currently don’t match the code paths they’re in).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| MainV2.cs | Adds guarded COM port dropdown population and updates error logging around connection/setup paths. |
| ExtLibs/Comms/CommsSerialPort.cs | Introduces timeout-based system COM enumeration with Windows registry fallback for resilience. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| catch (Exception ex) | ||
| { | ||
| log.Error(ex); | ||
| log.Error("Failed to enumerate serial ports for connection list.", ex); |
| catch (Exception ex) | ||
| { | ||
| log.Error(ex); | ||
| log.Error("Failed to populate serial port dropdown.", ex); |
Comment on lines
+327
to
+347
| private static string[] GetSystemPortNamesWithTimeout(int timeoutMilliseconds) | ||
| { | ||
| string[] ports = null; | ||
|
|
||
| try | ||
| { | ||
| CallWithTimeout(_ => { ports = System.IO.Ports.SerialPort.GetPortNames(); }, timeoutMilliseconds, 0); | ||
| } | ||
| catch (TimeoutException ex) | ||
| { | ||
| log.Warn($"System.IO.Ports.SerialPort.GetPortNames timed out after {timeoutMilliseconds} ms.", ex); | ||
| return null; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| log.Error("Unexpected error while enumerating system serial ports.", ex); | ||
| return null; | ||
| } | ||
|
|
||
| return ports ?? Array.Empty<string>(); | ||
| } |
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.
On some Windows 10 systems, opening or initializing the COM port selector could crash Mission Planner when Bluetooth serial drivers stall or misbehave during port enumeration. This change makes COM discovery resilient so the UI remains responsive and usable even when a driver hangs or throws.
Serial enumeration timeout + fallback
MissionPlanner.Comms.SerialPort.GetPortNames()no longer depends solely onSystem.IO.Ports.SerialPort.GetPortNames().HARDWARE\DEVICEMAP\SERIALCOMM.UI crash containment in port dropdown population
PopulateSerialportList()COM port insertion path in guarded error handling.Diagnostics improvements