Skip to content

Guard null Controller.Value in trigger hooks (fixes recurring 'Object reference not set', #178) - #187

Open
RTN-VMR wants to merge 1 commit into
Letaryat:mainfrom
RTN-VMR:fix/trigger-hooks-null-controller-guard
Open

Guard null Controller.Value in trigger hooks (fixes recurring 'Object reference not set', #178)#187
RTN-VMR wants to merge 1 commit into
Letaryat:mainfrom
RTN-VMR:fix/trigger-hooks-null-controller-guard

Conversation

@RTN-VMR

@RTN-VMR RTN-VMR commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Four trigger-output hooks in TriggerHooks.cs dereference a pawn's controller with .Value! and no null check:

var player = new CCSPlayerController(new CCSPlayerPawn(activator.Handle).Controller.Value!.Handle);

(the trigger_multiple OnStartTouch/OnEndTouch and the two trigger_teleport equivalents). When a pawn has no controller, transient during disconnect or a round/map transition, .Value is null and .Value!.Handle throws NullReferenceException. Each hook has a surrounding try/catch that logs Object reference not set to an instance of an object. and continues, so it is not fatal, but on a busy server it fires constantly and the repeated throw/catch is measurable overhead. This is the symptom reported in #178.

Fix

Resolve .Controller.Value into a local, null-check it, and return HookResult.Continue when null, identical to the existing activator == null guards already in these methods. Behaviour is unchanged when the controller is present. Applied to all four sites.

Testing

Built clean (0/0). Verified live on a surf server: the recurring trigger_multiple OnEndTouch "Object reference not set" spam is gone.

Closes #178.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ST-ERROR] Object reference not set to an instance of an object.

1 participant