Skip to content

fix(llf): guard against null bsLight/niLight#2140

Merged
doodlum merged 1 commit into
community-shaders:devfrom
alandtse:fix/llf-null-nilight
Apr 17, 2026
Merged

fix(llf): guard against null bsLight/niLight#2140
doodlum merged 1 commit into
community-shaders:devfrom
alandtse:fix/llf-null-nilight

Conversation

@alandtse
Copy link
Copy Markdown
Collaborator

@alandtse alandtse commented Apr 17, 2026

Null-check bsLight and niLight before dereferencing in BSLightingShader_SetupGeometry_GeometrySetupConstantPointLights. Use a write index so StrictLights[] stays contiguous when entries are skipped, and update NumStrictLights to the actual written count. Also guard the ShadowBitMask loop against null bsLight.

A BSLight can have a null NiLight smart pointer when the underlying light object is destroyed while still referenced in a render pass. Observed crash: RSI=null (niLight), RCX=0x110 (GetLightRuntimeData SE offset), +0x0C (diffuse) -> access at 0x11C.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed light rendering to properly handle complex lighting scenarios and prevent visual artifacts.
    • Improved shadow mask computation for more accurate lighting calculations across diverse scene conditions.
    • Enhanced overall rendering stability and quality in light-intensive environments.

Null-check bsLight and niLight before dereferencing in
BSLightingShader_SetupGeometry_GeometrySetupConstantPointLights.
Use a write index so StrictLights[] stays contiguous when entries
are skipped, and update NumStrictLights to the actual written count.
Also guard the ShadowBitMask loop against null bsLight.

A BSLight can have a null NiLight smart pointer when the underlying
light object is destroyed while still referenced in a render pass.
Observed crash: RSI=null (niLight), RCX=0x110 (GetLightRuntimeData
SE offset), +0x0C (diffuse) -> access at 0x11C.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 663ff29c-c0b0-49e1-8160-a3962cbbf205

📥 Commits

Reviewing files that changed from the base of the PR and between 4c0a4ea and ad7ce66.

📒 Files selected for processing (1)
  • src/Features/LightLimitFix.cpp

📝 Walkthrough

Walkthrough

Modified light population logic in the point lights setup function to skip null entries using a separate write index counter, ensuring only valid lights are stored and counted. Changed shadow mask bit-shifting from signed to unsigned integers for proper unsigned behavior.

Changes

Cohort / File(s) Summary
Light Population Fix
src/Features/LightLimitFix.cpp
Refactored strict light population to use a separate writeIdx counter, skipping null bsLight or niLight entries while maintaining a compact array. Updated NumStrictLights to reflect actual count. Changed shadow mask bit-shift from signed (1 << maskIndex) to unsigned (1u << maskIndex).

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly Related PRs

Suggested Reviewers

  • doodlum

Poem

🐰 Strict lights now skip the nulls with care,
A separate counter, placed just there,
No empty shadows in our array,
Unsigned shifts light the proper way!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding null checks for bsLight and niLight before dereferencing in light shader code.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

No actionable suggestions for changed features.

@github-actions
Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

@doodlum doodlum merged commit a847bd9 into community-shaders:dev Apr 17, 2026
17 checks passed
YtzyFvra pushed a commit to YtzyFvra/skyrim-community-shaders that referenced this pull request Apr 19, 2026
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants