risk-of-thunder / R2API

A modding API for Risk of Rain 2
https://thunderstore.io/package/tristanmcpherson/R2API/
MIT License
136 stars 55 forks source link

Fixed empty lobby browser #448

Closed KingEnderBrine closed 1 year ago

KingEnderBrine commented 1 year ago

The vanilla implementation of DifficultyCatalog.GetDifficultyDef() was handling out of bounds indices and just return null. And lobby browser would (I assume) display default difficulty which is rainstorm. R2API on the other hand was throwing an exception in such cases, but there's a catch, it all was executed in a not awaited Task, so any exception was just silent.

Logged stackTrace myself just out of curiosity:

StackTrace [Error :R2API.Difficulty] at R2API.DifficultyAPI.GetExtendedDifficultyDef (On.RoR2.DifficultyCatalog+orig_GetDifficultyDef orig, RoR2.DifficultyIndex difficultyIndex) [0x00000] in <9a72a7ea04974316b97f295c869a8f3a>:IL_0000 at DMD<>?503022336.Hook?-678958208 (RoR2.DifficultyIndex ) [0x00000] in <677b786581c54a81b079c89f1b51cf9f>:IL_0000 at RoR2.RemoteGameBrowser.AdvancedFilterRemoteGameProvider.g__PassesFilters|5_1 (RoR2.RemoteGameBrowser.RemoteGameInfo& remoteGameInfo, RoR2.RemoteGameBrowser.AdvancedFilterRemoteGameProvider+<>c__DisplayClass5_1& ) [0x00000] in :IL_0000 at RoR2.RemoteGameBrowser.AdvancedFilterRemoteGameProvider+<>c__DisplayClass5_0.b__0 () [0x00000] in :IL_0000 at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.Tasks.Task.Execute () [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.Tasks.Task.ExecutionContextCallback (System.Object obj) [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task& currentTaskSlot) [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.Tasks.Task.ExecuteEntry (System.Boolean bPreventDoubleExecution) [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <44afb4564e9347cf99a1865351ea8f4a>:IL_0000
xiaoxiao921 commented 1 year ago

Nice catch 👍