Fix NullReferenceException crashes when asset bundle is missing
Problem: When the 'serverbrowserpkg' asset bundle file is missing, the mod crashed at multiple points: - PrefabManager.PreScriptLoad(): NullReferenceException on line 58 - ServerBrowser.SceneLoaded(): "Object to instantiate is null" at line 312 - Main.TransitionTo(): NullReferenceException at lines 227-228 These crashes made the mod unusable and prevented proper error reporting. Root cause: The asset bundle file containing UI prefabs was missing from the mod directory, causing all prefab references to be null. The code didn't check for null before using these references. Solutions: PrefabManager.cs: - Add null check after LoadAssetBundle() call (line 31-36) - Return early with clear error message if bundle is null - Provide guidance to user about missing file - Better logging for successful loads ServerBrowser.SceneLoaded(): - Add prefab null check at method start (line 302-309) - Return early if prefabs are null - Prevents crash during UI instantiation - Clear error messages in log Main.TransitionTo(): - Add comprehensive null checks before using UI references (line 228) - If UI not loaded but user tries to access multiplayer menu: * Show user-friendly modal dialog * Explain the problem clearly * Provide reinstall guidance - Gracefully handle missing UI without crashing Results: ✅ No crashes when asset bundle is missing ✅ Clear, actionable error messages for users ✅ Graceful degradation - rest of mod still works ✅ User gets helpful modal instead of silent crash ✅ Better debugging with detailed logs Updated README.md with: - Documentation of all asset bundle fixes - Code examples showing the changes - Known Issues section noting missing asset bundle - Instructions for resolving the issue 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
73
README.md
73
README.md
@@ -219,9 +219,80 @@ Ezekkel a változtatásokkal a következő problémák lettek megoldva:
|
||||
2. Válaszd ki a servert a listából
|
||||
3. Kattints a "Join" gombra
|
||||
|
||||
### Asset Bundle hibák javítása (2025-12-14)
|
||||
|
||||
#### Probléma
|
||||
Ha az "serverbrowserpkg" asset bundle fájl hiányzik a mod könyvtárából, a mod NullReferenceException-öket dobott több helyen:
|
||||
- PrefabManager.PreScriptLoad(): Crash az asset bundle betöltésekor
|
||||
- ServerBrowser.SceneLoaded(): Crash amikor null prefab-okat próbált instantiate-lni
|
||||
- Main.TransitionTo(): Crash amikor null UI referenciákat próbált elérni
|
||||
|
||||
#### Megoldások
|
||||
|
||||
**PrefabManager.cs:31-36**
|
||||
- Null check az asset bundle betöltés után
|
||||
- Ha az asset bundle null, részletes hibaüzenet és early return
|
||||
- Egyértelmű útmutatás a felhasználónak
|
||||
|
||||
**ServerBrowser.cs:302-309**
|
||||
- Prefab null check a SceneLoaded elején
|
||||
- Ha a prefabok null-ok, részletes hibaüzenet és early return
|
||||
- Megakadályozza a crash-t és informálja a felhasználót
|
||||
|
||||
**Main.cs:228-244**
|
||||
- Null check minden UI referencia használata előtt
|
||||
- Ha a felhasználó a multiplayer menüt próbálja megnyitni de az UI nincs betöltve:
|
||||
- Részletes modal üzenet jelenik meg
|
||||
- A játék nem crash-el
|
||||
- Útmutatás a probléma megoldásához
|
||||
|
||||
**Érintett kód részletek:**
|
||||
```csharp
|
||||
// PrefabManager.cs
|
||||
if (assetBundle == null)
|
||||
{
|
||||
Main.helper.Log("ERROR: Asset bundle 'serverbrowserpkg' not found! UI features will not work.");
|
||||
Main.helper.Log("Please ensure the asset bundle file is in the mod directory.");
|
||||
return;
|
||||
}
|
||||
|
||||
// ServerBrowser.cs
|
||||
if (PrefabManager.serverBrowserPrefab == null || PrefabManager.serverLobbyPrefab == null)
|
||||
{
|
||||
Main.helper.Log("ERROR: UI prefabs not loaded. Asset bundle is missing.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Main.cs
|
||||
if (ServerBrowser.serverBrowserRef != null && ServerBrowser.serverLobbyRef != null)
|
||||
{
|
||||
// Safe to use UI references
|
||||
}
|
||||
else if ((int)state > 21)
|
||||
{
|
||||
// Show error modal instead of crashing
|
||||
ModalManager.ShowModal("Multiplayer Not Available", "...");
|
||||
}
|
||||
```
|
||||
|
||||
**Eredmények:**
|
||||
- ✅ Nincs crash ha az asset bundle hiányzik
|
||||
- ✅ Világos hibaüzenetek a felhasználónak
|
||||
- ✅ Graceful degradation - a mod többi része működik
|
||||
- ✅ Útmutatás a probléma megoldásához
|
||||
|
||||
**MEGJEGYZÉS:** Az asset bundle fájl jelenleg hiányzik a mod könyvtárából. A multiplayer UI funkciók működéséhez szükséges a "serverbrowserpkg" fájl hozzáadása.
|
||||
|
||||
## Ismert problémák
|
||||
|
||||
Jelenleg nincsenek ismert kritikus problémák. Ha hibát találsz, kérlek jelentsd a fejlesztőknek.
|
||||
1. **Hiányzó Asset Bundle**: A "serverbrowserpkg" asset bundle fájl jelenleg hiányzik a mod könyvtárából. Ez azt jelenti, hogy:
|
||||
- A multiplayer UI (Server Browser, Server Lobby) nem jelenik meg
|
||||
- A Multiplayer gomb a főmenüben hibaüzenetet fog mutatni
|
||||
- A mod többi része (connection handling, stb.) továbbra is működik
|
||||
|
||||
**Megoldás:** Helyezd el a "serverbrowserpkg" fájlt a mod gyökérkönyvtárába és indítsd újra a játékot.
|
||||
|
||||
Ha egyéb hibát találsz, kérlek jelentsd a fejlesztőknek.
|
||||
|
||||
## Fejlesztői megjegyzések
|
||||
|
||||
|
||||
Reference in New Issue
Block a user