Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects

Infinite hang when reloading a scene contains a manually spawned NetworkObject with a SpriteLibrary and a SpriteResolver

未關閉
#4,095 10 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stat:reply-needed type:support
主要語言
C#
星號
2.3k
分支
461
平均合併
3 天 16 小時
30 天內合併 PR
20

描述

Description

Infinite hang when reloading a scene contains a manually spawned NetworkObject with a SpriteLibrary and a SpriteResolver

Reproduce Steps
  1. Create an empty scene
  2. Add a NetworkManager, with UnityTransport
  3. Create a new prefab with NetworkObject, SpriteRenderer, Animator, SpriteLibrary, SpriteResolver (following basically this tutorial: https://www.youtube.com/watch?v=4xPHqEEa-V0)
  4. Create an empty object TestCrash with the following code, and link the prefab from (3) in the inspector
public class TestCrash : NetworkBehaviour
{
    [SerializeField] public GameObject prefab = null!;
    private bool _alreadyCalled;

    private void Start()
    {
        var networkManager = NetworkManager.Singleton;
        var unityTransport = networkManager.GetComponent<UnityTransport>();

        // Start local server
        unityTransport.UseWebSockets = false; // if applicable
        unityTransport.SetConnectionData("0.0.0.0", 7777);
        networkManager!.NetworkConfig.NetworkTransport = unityTransport;
        networkManager.StartHost();

        NetworkManager.Singleton.SpawnManager.InstantiateAndSpawn(
            prefab!.GetComponent<NetworkObject>(),
            OwnerClientId,
            destroyWithScene: true,
            position: Vector3.zero
        );
    }

    private void Update()
    {
        if (_alreadyCalled) return;
        if (Time.timeSinceLevelLoad < 3f) return;
        _alreadyCalled = true;
       NetworkManager.Singleton.SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
    }
}

TestCrash is some code that

  • starts a local server
  • spawns the prefab
  • waits 3 seconds
  • reloads the scene
Actual Outcome

After a few attempts, the scene never reloads and the Unity editor hangs forever (has to be force quitted)

Expected Outcome

The scene reloads every 3s

Environment
  • OS: Windows 11
  • Unity Version: 6000.4.7f1
  • Netcode Version: 2.12.0
Additional Context
  • This bug did not happen with 2.12.0 and Unity 6000.3.11f1 (started happening after upgrading to 6000.4.7f1)
  • The bug doesn't happen without destroyWithScene: true,
  • Removing the SpriteResolver/SpriteLibrary stops the bug from happening
  • The NetworkObject must be spawned with InstantiateAndSpawn, if the prefab is added to the scene, the bug doesn't happen

Here is a dump of the Main Thread stack when the editor is hanging. The CPU is at 0% at that point. Maybe a lock contention?

<unknown> 0x00007ff973d63cb4
<unknown> 0x00007ff973c30543
<unknown> 0x00007ff97107e558
UnityClassic::Baselib_SystemFutex_Wait(int * __ptr64,int,unsigned int) 0x00007ff8886af7f6
ProfilerMutexLock(Mutex & __ptr64,char const * __ptr64,profiling::Marker & __ptr64,char const * __ptr64,int) 0x00007ff88b1a4450
PersistentManager::Lock(PersistentManager::LockFlags,profiling::Marker * __ptr64) __ptr64 0x00007ff88b1a1b83
PersistentManager::GetPathName(EntityId) __ptr64 0x00007ff88b1968bb
GetGUIDFromEntityId(EntityId) 0x00007ff888e786fe
AssetChangedNotifier::UnsubscribeFromAll(EntityId) __ptr64 0x00007ff88a209aee
SpriteRenderer::MainThreadCleanup(void) __ptr64 0x00007ff88b631e42
delete_object_internal_step1(Object * __ptr64) 0x00007ff88b8cd380
CommitBatchDelete(BatchDelete & __ptr64) 0x00007ff88b5286d2
DestroyObjectHighLevel_Internal(Object * __ptr64,bool) 0x00007ff88b532e31
DestroyObjectHighLevel(Object * __ptr64,bool) 0x00007ff88b532ba8
DelayedDestroyCallback(Object * __ptr64,void * __ptr64) 0x00007ff88b7963cb
DelayedCallManager::Update(int) __ptr64 0x00007ff88b797ac8
<unknown> 0x00007ff88b4f9d6b
ExecutePlayerLoop(NativePlayerLoopSystem * __ptr64) 0x00007ff88b517f5b
ExecutePlayerLoop(NativePlayerLoopSystem * __ptr64) 0x00007ff88b51811a
PlayerLoop(void) 0x00007ff88b51d105
EditorPlayerLoop::Execute(void) __ptr64 0x00007ff889ab957a
PlayerLoopController::InternalUpdateScene(bool,bool) __ptr64 0x00007ff889ab2a9c
PlayerLoopController::UpdateSceneIfNeededFromMainLoop(void) __ptr64 0x00007ff889ab4dad
Application::TickTimer(void) __ptr64 0x00007ff889acc4c3
<unknown> 0x00007ff8894bfb2c
UnityMain 0x00007ff8894c8693
<unknown> 0x00007ff6ae972f2a
<unknown> 0x00007ff97360e957
<unknown> 0x00007ff973caad6c

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先重現啟用 NetworkManager、UnityTransport、InstantiateAndSpawn、SpriteLibrary、SpriteResolver 和 destroyWithScene 的設定,然後在反覆重新載入期間追蹤 NetworkManager.SceneManager.LoadScene。比較所回報的 Unity 和 Netcode 版本之間的行為;完成的標準是場景每 3 秒重新載入一次,且 Unity 編輯器不會卡住。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp, unity
領域
game-dev, networking
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。