Bug Description
NullReferenceException occurs in MCPForUnityEditorWindow.ScheduleHealthCheck() when the window is closed but delayed callback still executes.
Stack Trace
NullReferenceException: Object reference not set to an instance of an object
MCPForUnity.Editor.Windows.MCPForUnityEditorWindow.<ScheduleHealthCheck>b__12_0 () (at ./Library/PackageCache/com.coplaydev.unity-mcp@81ef4be7614d/Editor/Windows/MCPForUnityEditorWindow.cs:170)
Problem
Line 170 uses await connectionSection?.VerifyBridgeConnectionAsync();
The null-conditional operator ?. returns null, but await null throws NullReferenceException.
Suggested Fix
private void ScheduleHealthCheck()
{
EditorApplication.delayCall += async () =>
{
if (this == null || connectionSection == null)
{
return;
}
await connectionSection.VerifyBridgeConnectionAsync();
};
}
Explicit null check before awaiting prevents the exception.
Environment
- Unity Version: 6.2 (6000.2.12f1)
- Package Version: com.coplaydev.unity-mcp@81ef4be7614d
Bug Description
NullReferenceExceptionoccurs inMCPForUnityEditorWindow.ScheduleHealthCheck()when the window is closed but delayed callback still executes.Stack Trace
Problem
Line 170 uses
await connectionSection?.VerifyBridgeConnectionAsync();The null-conditional operator
?.returns null, butawait nullthrows NullReferenceException.Suggested Fix
Explicit null check before awaiting prevents the exception.
Environment