Skip to content

Conversation

@AussieScorcher
Copy link
Member

Summary

This pull request delivers a set of improvements aimed at making SimConnect.NET more reliable, predictable, and easier to diagnose. It introduces safer exception handling across all background loops, improves struct based SimVar writing, strengthens input event parsing, and updates integration tests for better stability. The release also bumps the version to 0.1.17 and updates the changelog.

Changes Made

  • Added a central ExceptionHelper and updated all major background loops to swallow only non critical exceptions while allowing critical ones to surface, improving safety and observability
  • Refined diagnostics in the SimConnect client and logger, including clearer cancellation logging and level gated debug output
  • Improved struct based SimVar writing with cached writers, strict ANSI encoding rules, and better error surfacing, plus added support for automatic type inference for SimConnectDataInitPosition
  • Hardened input event enumeration and parsing with safer fallbacks, guarded decoding, and defensive try get helpers
  • Updated subscription callback behaviour to log user exceptions without crashing the SimConnect thread
  • Improved integration test stability by reusing a single SimConnectClient, switching AI object offset calculations to double arithmetic, and simplifying unused locals
  • Performed small code cleanups including LINQ based container title enumeration
  • Bumped the package version to 0.1.17 and updated the changelog accordingly

Additional Information

These changes collectively make exception behaviour more predictable, improve SimVar struct layout correctness, reduce hidden crashes in user code paths, and strengthen the overall test harness to prevent intermittent failures.

Author Information

Discord Username: AussieScorcher


Checklist:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update or change?

bstudtma and others added 2 commits October 21, 2025 18:28
…12)

* Add struct-based SimVar set functionality

Introduces IFieldWriter, SimVarFieldWriter, and SimVarFieldWriterFactory to enable writing SimVar-annotated structs into unmanaged buffers. Adds SimVarManager.SetAsync<T> and SetStructAsync for setting multiple SimVars in one call using a struct. Updates tests to verify struct-based SimVar setting and restoration.

* Improve SimConnect struct writing and error handling

Refactored string field writing to ensure explicit null-termination and use Latin1 encoding for SimConnect compatibility. Added caching of struct writers and total size in SimVarManager for efficient SetDataOnSimObject calls. Improved error handling and updated attribute references from [SimVar] to [SimConnect].
- Added ExceptionHelper for improved exception handling in various components.
- Enhanced SimVar type inference for automatic detection of SimConnectDataInitPosition.
- Improved struct-based SimVars.SetAsync<TStruct> for better performance and error handling.
- Updated logging mechanisms to use ExceptionHelper for critical exception filtering.
- Refined input event processing with defensive coding practices.
- Maintained integration tests for better coverage and reliability.
- Fixed issues with struct writers and SimVarManager logging.
llamavert
llamavert previously approved these changes Nov 14, 2025
Copy link
Contributor

@llamavert llamavert left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces version 0.1.17 of SimConnect.NET with improvements focused on exception handling, struct-based SimVar operations, input event parsing robustness, and test infrastructure stability.

  • Adds a central ExceptionHelper to distinguish critical from non-critical exceptions across background loops
  • Enhances struct-based SimVar writing with cached writers and improved ANSI string encoding
  • Strengthens input event parsing with defensive fallbacks and guarded type conversions

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Directory.Build.props Bumps package version to 0.1.17
CHANGELOG.md Documents all changes in version 0.1.17
src/SimConnect.NET/Internal/ExceptionHelper.cs Adds new helper to identify critical exceptions that should not be swallowed
src/SimConnect.NET/SimConnectClient.cs Adds exception filtering and improves cancellation logging
src/SimConnect.NET/SimConnectLogger.cs Adds exception filtering, improves error reporting, and uses Path.Join
src/SimConnect.NET/SimVar/SimVarManager.cs Adds cached struct writers, exception filtering, null-unit support, and type inference for SimConnectDataInitPosition
src/SimConnect.NET/SimVar/Internal/SimVarRequest.cs Adds exception filtering and logging for user callback errors
src/SimConnect.NET/SimVar/Internal/SimVarFieldReaderFactory.cs Updates error message to reference [SimConnect] attribute
src/SimConnect.NET/SimVar/Internal/SimVarFieldWriterFactory.cs Updates error message and removes dead code assignment
src/SimConnect.NET/SimVar/Internal/SimVarFieldWriter.cs Refactors string encoding to use Latin1 with explicit null termination
src/SimConnect.NET/InputEvents/InputEventManager.cs Adds exception filtering and defensive input event parsing
src/SimConnect.NET/InputEvents/InputEventValue.cs Refines exception handling in TryGetDoubleValue and simplifies TryGetStringValue
src/SimConnect.NET/AI/SimObjectType.cs Refactors GetAllContainerTitles to use LINQ
tests/SimConnect.NET.Tests.Net8/Tests/TestRunner.cs Refactors to reuse single SimConnectClient and updates test iteration
tests/SimConnect.NET.Tests.Net8/Tests/ConnectionTests.cs Replaces unused local variables with discard operator
tests/SimConnect.NET.Tests.Net8/Tests/AIObjectTests.cs Uses explicit double casts for position offset calculations
Comments suppressed due to low confidence (1)

tests/SimConnect.NET.Tests.Net8/Tests/TestRunner.cs:121

            foreach (var resultTask in testsToRun.Select(test => this.RunSingleTestAsync(test)))
            {
                var result = await resultTask;
                results.Add(result);

                if (!result.Passed && options.StopOnFirstFailure)
                {
                    Console.WriteLine("🛑 Stopping on first failure as requested");
                    break;
                }

                // Small delay between tests
                await Task.Delay(500);
                Console.WriteLine();
            }

@AussieScorcher AussieScorcher merged commit f606b9c into main Nov 14, 2025
6 checks passed
@AussieScorcher AussieScorcher deleted the 0.1.17 branch November 14, 2025 10:32
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.

4 participants