Scope: Assets/UnityHiroChallenges/Scripts, Assets/UnityHiroChallenges/Editor, Assets/UnityHiroChallenges/HeroicUI
Click to expand resolved issues from initial review
-
View created with discard operator, never disposedFIXED: ChallengesViewBehaviour now manages View lifecycle and calls Dispose() in OnDestroy(). -
Null check missing before subscribing to coordinatorFIXED: Null checks are in place before subscribing to coordinator events. -
LINQ usage -FIXED: Replaced with reverse for-loop.RemoveAllviolates project guideline. -
Inconsistent logging - Mix ofFIXED: All exception logging now usesDebug.Log(e)andDebug.LogException(e).Debug.LogException(e)consistently. -
OnCoordinatorReady infinite loop -FIXED: Refactored to use TaskCompletionSource pattern with proper error handling.while (!_controller.IsInitialized) await Task.Yield()without timeout or error check. -
difference.Seconds vs TotalSeconds - UsesFIXED: Changed todifference.Seconds > 0which is only the seconds component, mislabeling challenges.difference.TotalSeconds > 0. -
_challengesList.selectionChanged not cleaned upFIXED: Now unsubscribed in Dispose(). -
_challengesSystemObserver declared but never assignedFIXED: Removed unused field.
-
Unused fieldsNOT AN ISSUE: Required for ListView_challengeEntryTemplateand_challengeParticipantTemplatemakeItemcallbacks. -
Double blank lines - minor style issue.FIXED: Removed double blank lines. -
Dispose doesn't unsubscribe from coordinator eventFIXED: ChallengesViewBehaviour handles coordinator subscription/unsubscription.
-
LINQ usage -FIXED: All LINQ removed. Uses foreach loops and List.Sort().using System.Linqand multiple LINQ calls. -
Public field instead of property -FIXED: Now usesCurrentUserIdwas a public field.public string CurrentUserId { get; private set; } -
Mutable list exposed publicly - WON'T FIX
ListView.itemsSourcerequiresIList, soChallengesmust remainList<IChallenge>. UsingIReadOnlyListwould require duplicating the list in the view. -
GetTemplate(int) relies on Dictionary order -FIXED: Now stores ordered list of templates and indexes into that.ElementAt()is not stable across runs. -
Subscribes to coordinator events but never unsubscribesFIXED: Controller is now plain C# class; ChallengesViewBehaviour handles lifecycle. -
async void handlers lack try/catchFIXED: All async void handlers now have try/catch.
-
Unnecessary KeyValuePair allocationFIXED: Refactored to use templates directly. -
DTOs at bottom should be separate file or use records - WON'T FIX Unity's .NET runtime lacks
System.Runtime.CompilerServices.IsExternalInit, required for C# records. A polyfill exists but adds complexity for minimal benefit in a sample project.
UsesFIXED: Removed unsupported markup.<color=blue>in UI Toolkit Label - UI Toolkit does not support rich text by default.
-
Unsafe cast without null checkFIXED: Now uses pattern matching (is not Session session) with descriptiveInvalidOperationExceptionon type mismatch. -
Static event - memory leak risk - ACCEPTABLE Static events can hold references to subscribers indefinitely. Current subscribers (
ChallengesView) properly unsubscribe inDispose(). Risk is documented; no code change needed. -
PlayerPrefs not savedFIXED: AddedPlayerPrefs.Save()afterSetStringinSaveCache().
-
Cache reset inconsistencyFIXED: AddedPlayerPrefs.Save()afterDeleteKeyinClearAccounts()for consistency. -
EnsureAccountsExistAsync fires AccountSwitched multiple timesFIXED: ExtractedAuthenticateAndStoreAccountAsyncandApplySessionAsyncprivate methods.
OnCoordinatorInitialized throws when coordinator is missingFIXED: Now uses graceful handling with error logging instead of throwing.
-
float.Parse without culture - can failFIXED: Now usesfloat.TryParsewithCultureInfo.InvariantCulture. -
Fire-and-forget async without error handlingFIXED:OnEconomyUpdatedis now async void with try/catch. -
CancellationTokenSource not disposedFIXED: Old CTS is now disposed before creating a new one. -
Task.Delay with Time.deltaTime is problematicFIXED: Now uses fixedFrameDelaySeconds(0.016s / ~60fps). -
Dispose doesn't cancel running tasksFIXED:Dispose()now cancels and disposes both CTS instances.
- Hard-coded server key and PlayerPrefs tokens - WON'T FIX Intentional for demo project. Server is configured specifically for this sample.
-
Tight coupling:FIXED: Now uses staticAccountSwitchertakesChallengesControlleras parameter.AccountSwitchedevent for decoupling. -
View instantiation: Controller creates View but doesn't manage its lifecycle.FIXED: ChallengesViewBehaviour (MonoBehaviour) now creates and manages View lifecycle. -
No CancellationToken propagation: Long-running operations don't support cancellation.FIXED: ChallengesView now has aCancellationTokenSourcecancelled inDispose(). -
Mixed responsibilities:FIXED: ChallengesController is now a plain C# class with constructor injection.ChallengesControlleris both MonoBehaviour and business logic.
-
Race condition: CancellationTokenSource not thread-safe(Lines 90, 156-162) FIXED: Added_disposedvolatile flag with lock inDispose(). NewThrowIfDisposedOrCancelled()helper checks disposed state before accessing_cts.Token, preventingObjectDisposedException. -
Null reference in UpdateSelectedChallengePanel(Line 532) FIXED:ChallengesController.SelectChallengeAsyncnow returns empty list instead of null. Follows best practice of never returning null for collections. -
Fire-and-forget async pattern (Line 114)
_ = InitializeAsync();
Discarding the task means exceptions are silently swallowed even with try/catch (unobserved task exceptions).
-
Tight coupling to static AccountSwitcher (Lines 112, 404, 716, 859) View has direct static dependency on
AccountSwitcher. Violates dependency injection principles and makes testing harder. -
No validation on user input in CreateChallenge (Lines 711-743) No validation of
_modalNameField.value(could be empty),_modalMaxParticipantsField.value, or parsed invitee IDs before calling controller.
- Missing null checks on UI elements (Lines 33-40)
SetVisualElementqueries UI elements but doesn't validate they exist:If UXML template is missing elements,_nameLabel = visualElement.Q<Label>("name"); // Could be null
SetChallengewill throw NullReferenceException.
- Missing null checks on UI elements (Lines 30-36)
Same issue as ChallengeView - no validation after
Q<>()queries.
- CancellationTokenSource lifecycle risk (Lines 60-69)
If
HandleWalletUpdatedAsyncis called rapidly, the old CTS is disposed while the previous task may still be using its token, potentially causingObjectDisposedException.
- Editor window null reference risk (Lines 57, 110)
Accesses
HiroCoordinator.Instancewhich could be null when not in play mode or after domain reload. While null checks exist, the code pattern is fragile.
- No event notification on account switch (Lines 53-59)
SwitchCompleteAsyncclears state but doesn't notify observers. View must manually callRefreshChallengesAsync.
-
No timeout on async operations Async operations like
RefreshChallengesAsynchave no timeout. Spinner could spin forever if server hangs. -
Magic strings for date format (ChallengesView.cs:556)
endTime.ToString("MMM dd, HH:mm")
Should be a constant.
- Clean MVP Architecture: Proper separation between Controller (business logic), View (UI), and ViewBehaviour (MonoBehaviour lifecycle)
- Dependency Injection: Constructor validation with
ArgumentNullException - Async/Await Patterns: Proper cancellation token support and error handling
- UI Toolkit Best Practices:
RequireElementpattern for fail-fast on missing UI - Comprehensive Tests: Integration tests cover real user flows
- Resource Cleanup: Proper
IDisposableimplementation throughout - Extension Methods: Clean
Show/Hide/SetDisplayhelpers - User-Friendly Errors:
ShowError()pattern for consistent error display
| Severity | Original | Remaining |
|---|---|---|
| Critical | 16 | 0 |
| Medium | 10 | 0 |
| Severity | Count |
|---|---|
| Critical | 1 |
| Medium | 6 |
| Low | 3 |
- Fix
_ctsrace condition - add synchronization or use single-operation pattern - Add null check for
participantsinUpdateSelectedChallengePanel - Add null validation for UI elements in
ChallengeViewandChallengeParticipantView - Review
WalletDisplayCTS lifecycle for rapid updates - Add input validation in
CreateChallenge