Skip to content

Commit

Permalink
fix: use sync gRPC to destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
DiscreteTom committed Jun 2, 2023
1 parent 13b3443 commit 67d5a62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Assets/HDD/Scripts/HDD_Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Awake() {
}

public async Task Refresh() {
await this.DestroyAllMonitors();
this.DestroyAllMonitors();
await this.client.RestartAsync(new Shremdup.RestartRequest { });
// list displays
var reply = await this.client.ListDisplaysAsync(new Shremdup.ListDisplaysRequest { });
Expand All @@ -46,25 +46,25 @@ public GameObject CreateMonitor(int id) {
return monitor;
}

async void OnDestroy() {
void OnDestroy() {
// first, destroy all monitors
await this.DestroyAllMonitors();
this.DestroyAllMonitors();

// then close the channel
try {
await channel.ShutdownAsync();
channel.ShutdownAsync().Wait();
Logger.Log("channel shutdown");
} catch {
Logger.Log("channel not shutdown");
}
}

async Task DestroyAllMonitors() {
void DestroyAllMonitors() {
var monitors = GetComponentsInChildren<HDD_Monitor>();
for (var i = 0; i < monitors.Length; ++i) {
var monitor = monitors[i];
try {
await monitor.DestroyMonitor();
monitor.DestroyMonitor();
} catch (System.Exception e) {
Logger.Log($"error destroying monitor {i}: {e}");
}
Expand Down
8 changes: 4 additions & 4 deletions Assets/HDD/Scripts/HDD_Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void Update() {
if (this.state == State.TakeCaptureDone && this.desktopRenderer.visible) this.TakeCapture();
}

public async Task DestroyMonitor() {
public void DestroyMonitor() {
if (this.destroyed) return;
this.destroyed = true;

Expand All @@ -257,16 +257,16 @@ public async Task DestroyMonitor() {

// stop server capture
try {
await client.DeleteCaptureAsync(new Shremdup.DeleteCaptureRequest { Id = (uint)this.id });
client.DeleteCapture(new Shremdup.DeleteCaptureRequest { Id = (uint)this.id });
Logger.Log($"display {this.id}: capture deleted");
} catch (Exception e) {
Logger.Log($"display {this.id}: delete capture failed: {e}");
}
}

async void OnDestroy() {
void OnDestroy() {
if (!this.destroyed)
await this.DestroyMonitor();
this.DestroyMonitor();
}
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v1.2.2

- Fix: use the sync version gRPC call to make sure `HDD_Monitor/HDD_Manager` are properly destroyed.

## v1.2.1

- Enhance stability.
Expand Down

0 comments on commit 67d5a62

Please sign in to comment.