Keep provider subscriptions valid through teardown
This commit is contained in:
parent
69ede37253
commit
ddd2c5871f
3 changed files with 31 additions and 11 deletions
|
|
@ -70,17 +70,9 @@ namespace GameCult.Eve.UnityScene
|
|||
}
|
||||
}
|
||||
|
||||
public event Action<EveUnitySceneProviderSurfaceDocument>? DocumentAvailable
|
||||
{
|
||||
add { Bridge.DocumentAvailable += value; }
|
||||
remove { Bridge.DocumentAvailable -= value; }
|
||||
}
|
||||
public event Action<EveUnitySceneProviderSurfaceDocument>? DocumentAvailable;
|
||||
|
||||
public event Action<EveUnitySceneCommandReceipt>? ReceiptAvailable
|
||||
{
|
||||
add { Bridge.ReceiptAvailable += value; }
|
||||
remove { Bridge.ReceiptAvailable -= value; }
|
||||
}
|
||||
public event Action<EveUnitySceneCommandReceipt>? ReceiptAvailable;
|
||||
|
||||
public void Configure(
|
||||
string endpoint,
|
||||
|
|
@ -163,6 +155,11 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_bridge != null)
|
||||
{
|
||||
_bridge.DocumentAvailable -= ForwardDocument;
|
||||
_bridge.ReceiptAvailable -= ForwardReceipt;
|
||||
}
|
||||
_bridge?.Dispose();
|
||||
_transport?.Dispose();
|
||||
while (_pendingEntityViews.TryDequeue(out var pending)) pending.Lease.Dispose();
|
||||
|
|
@ -230,9 +227,17 @@ namespace GameCult.Eve.UnityScene
|
|||
_transport.EntityViewAvailable += (view, lease) => _pendingEntityViews.Enqueue(new EntityViewLease(view, lease));
|
||||
_transport.FieldsSplatsAvailable += fields => _pendingFields.Enqueue(fields);
|
||||
_bridge = new EveUnitySceneLiveProviderBridge(_transport);
|
||||
_bridge.DocumentAvailable += ForwardDocument;
|
||||
_bridge.ReceiptAvailable += ForwardReceipt;
|
||||
TraceStartup($"transport-construction {elapsed.Elapsed.TotalMilliseconds:0.###}ms");
|
||||
}
|
||||
|
||||
private void ForwardDocument(EveUnitySceneProviderSurfaceDocument document) =>
|
||||
DocumentAvailable?.Invoke(document);
|
||||
|
||||
private void ForwardReceipt(EveUnitySceneCommandReceipt receipt) =>
|
||||
ReceiptAvailable?.Invoke(receipt);
|
||||
|
||||
private static void TraceStartup(string message)
|
||||
{
|
||||
if (string.Equals(Environment.GetEnvironmentVariable("EVEUNITY_TRACE_STARTUP_PHASES"), "1", StringComparison.Ordinal))
|
||||
|
|
|
|||
|
|
@ -52,6 +52,21 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProviderSubscriptionsDoNotDependOnPreparedTransportLifetime()
|
||||
{
|
||||
var gameObject = new GameObject("unprepared-eve-provider-subscriptions");
|
||||
var provider = gameObject.AddComponent<EveUnityCultMeshPlayableWorldProvider>();
|
||||
Action<EveUnitySceneProviderSurfaceDocument> documentHandler = _ => { };
|
||||
Action<EveUnitySceneCommandReceipt> receiptHandler = _ => { };
|
||||
|
||||
Assert.DoesNotThrow(() => provider.DocumentAvailable += documentHandler);
|
||||
Assert.DoesNotThrow(() => provider.ReceiptAvailable += receiptHandler);
|
||||
Assert.DoesNotThrow(() => provider.DocumentAvailable -= documentHandler);
|
||||
Assert.DoesNotThrow(() => provider.ReceiptAvailable -= receiptHandler);
|
||||
Assert.DoesNotThrow(() => UnityEngine.Object.DestroyImmediate(gameObject));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResolvesUnityNormalizedBundleNamesWithoutChangingLogicalAssetIdentity()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "org.gamecult.eve.unity-scene",
|
||||
"displayName": "Eve Unity Scene Lowering",
|
||||
"version": "0.3.101",
|
||||
"version": "0.3.102",
|
||||
"unity": "6000.0",
|
||||
"description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.",
|
||||
"dependencies": {
|
||||
|
|
|
|||
Reference in a new issue