Skip to content

Add delay time option when debugging unity games #189

@UlyssesWu

Description

@UlyssesWu

for (;;) {
var elapsedTime = DateTime.UtcNow - startTime;
if (elapsedTime >= connectionTimeout)
throw new CouldNotConnectException(GetCouldNotConnectErrorMessage(connectionAddress, connectionPort, filename));
try {
var cts = new CancellationTokenSource(connectionTimeout - elapsedTime);
var asyncConn = VirtualMachineManager.ConnectAsync(endPoint, null, cts.Token);
if (!asyncConn.Wait(connectionTimeout - elapsedTime))
throw new CouldNotConnectException(GetCouldNotConnectErrorMessage(connectionAddress, connectionPort, filename));
vm = asyncConn.Result;
break;
}
catch (SocketException sex) when (sex.SocketErrorCode == SocketError.ConnectionRefused) {
// Retry it in case it takes a while for mono.exe to initialize or if it hasn't started yet
}
Thread.Sleep(100);
}

When debugging unity games uisng Start Debugging, the process may not start very quickly.
Currently dnspy will immediately try to connect the socket, but the game port is not ready.
Then, a AggregateException with a SocketException inside will be thrown (not just a SocketException),
making the debugging fail with the error Error_CouldNotConnectToProcess.
But the expect behavior should be: keep trying until it reaches timeout (30s by default).

To fix this, we can catch both AggregateException and SocketException, or add a delay time option in Start Debugging window.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions