Skip to content

Commit caeff54

Browse files
Address object creation review feedback
1 parent fdd2a8e commit caeff54

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/SimConnect.NET/AI/SimObjectManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,13 @@ private async Task<int> InvokeObjectCreationAsync(
487487
{
488488
registerPacketId(sendId, requestId);
489489
}
490+
else
491+
{
492+
SimConnectLogger.Warning(
493+
$"SimObjectManager: Created object request {requestId}, but packet ID lookup failed: {SimConnectErrorMapper.Format(packetIdResult)}. Server errors cannot be correlated for this request.");
494+
}
490495

491-
return packetIdResult;
496+
return (int)SimConnectError.None;
492497
},
493498
cancellationToken).ConfigureAwait(false);
494499
}

src/SimConnect.NET/SimConnectClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ internal async Task<bool> GetIsMSFS2024Async(CancellationToken cancellationToken
661661
throw new InvalidOperationException("Simulator identification is unavailable because SimConnect is not connected.");
662662
}
663663

664-
return await identification.Task.WaitAsync(TimeSpan.FromSeconds(5), cancellationToken).ConfigureAwait(false);
664+
return await identification.Task.WaitAsync(cancellationToken).ConfigureAwait(false);
665665
}
666666

667667
/// <summary>

tests/SimConnect.NET.UnitTests/SimObjectManagerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,31 @@ public async Task SuccessRemovesNativePacketMapping()
103103
Assert.Equal(123u, created.ObjectId);
104104
Assert.False(manager.TryResolveRequestId(nativeSendId, out _));
105105
}
106+
107+
/// <summary>
108+
/// Verifies creation can complete when native packet correlation is unavailable.
109+
/// </summary>
110+
[Fact]
111+
public async Task SuccessWithoutPacketMappingStillCompletes()
112+
{
113+
uint clientRequestId = 0;
114+
var nativeCallCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
115+
using var client = new SimConnectClient("Unit test");
116+
using var manager = new SimObjectManager(
117+
client,
118+
(title, livery, position, requestId, registerPacketId, cancellationToken) =>
119+
{
120+
clientRequestId = requestId;
121+
nativeCallCompleted.SetResult();
122+
return Task.FromResult((int)SimConnectError.None);
123+
},
124+
TimeSpan.FromSeconds(10));
125+
126+
var creation = manager.CreateObjectAsync("CoffeeCup", default);
127+
await nativeCallCompleted.Task.WaitAsync(TimeSpan.FromSeconds(1));
128+
manager.ProcessObjectCreated(clientRequestId, 123, string.Empty, default);
129+
130+
var created = await creation;
131+
Assert.Equal(123u, created.ObjectId);
132+
}
106133
}

0 commit comments

Comments
 (0)