Skip to content

fix(TerrainShadows): clear stale heightmap cache on worldspace transitions#1676

Closed
Copilot wants to merge 4 commits into
devfrom
copilot/fix-terrain-shadows-markarth
Closed

fix(TerrainShadows): clear stale heightmap cache on worldspace transitions#1676
Copilot wants to merge 4 commits into
devfrom
copilot/fix-terrain-shadows-markarth

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 4, 2026

  • Understand the issue: Terrain shadows breaking in Markarth due to stale heightmap cache
  • Analyze code: Review TerrainShadows.cpp LoadHeightmap() and related functions
  • Identify root cause: cachedHeightmap not cleared when entering worldspace without heightmap
  • Implement fix: Clear cached heightmap when worldspace has no heightmap
  • Add interior/special worldspace detection: Prevent terrain shadows in interior-like worldspaces
  • Add enhanced debug information to help diagnose issues
  • Run pre-commit checks: All formatting checks passed
  • Run code review: No issues found
  • Run security scan: No vulnerabilities detected
  • Verify enum values: Confirmed kNoSky and kFixedDimensions are valid in CommonLibSSE-NG
  • Remove extraneous files: Removed _codeql_detected_source_root and updated .gitignore
  • Confirm build (Windows-only - cannot verify in Linux environment)
  • Complete and finalize

Summary

Fixed terrain shadows breaking in Markarth and similar worldspaces by properly clearing the heightmap cache when transitioning to worldspaces without heightmaps.

Enum Verification: Confirmed that RE::TESWorldSpace::Flag::kNoSky and RE::TESWorldSpace::Flag::kFixedDimensions are valid enum values in CommonLibSSE-NG (lines 133-134 of TESWorldSpace.h). Usage pattern matches existing code in src/Utils/Game.cpp:308.

Root Cause: The LoadHeightmap() function retained stale heightmap data from previous worldspaces, causing incorrect shadow rendering or display of wrong heightmap data in the debug UI.

Solution:

  1. Clear cachedHeightmap, texHeightMap, and texShadowHeight when:
    • No worldspace is active
    • Current worldspace has no heightmap
    • Worldspace has interior-like flags (kNoSky or kFixedDimensions)
  2. Enhanced debug UI with additional diagnostic fields for troubleshooting
  3. Removed extraneous CodeQL artifact file

Build Note: This is a Windows-only project requiring Visual Studio. The code changes follow existing patterns in the codebase and use verified CommonLibSSE-NG enum values.

Original prompt

This section details on the original issue you should resolve

<issue_title>CS 1.4.6 Terrain shadows breaking in Markarth</issue_title>
<issue_description>This is an issue I have been seeing since at least CS 1.3.6.
Terrain Shadows are not filtered and seem to be using the wrong heightmap in the Markarth worldspace.
I am not sure if this happens in Markarth only or also in other places, however I have observed that this issue is inconsistent.
Normally in markarth no Terrain shadows are applied, and the debug menu shows the most recent active heightmap from the previous worldspace.
Sometimes however it does start using the heightmap and the data is being updated in markarth, leading to broken shadows.
https://streamable.com/sjmnq2

How it would normally look like (Note how the heightmap in use is from a different worldspace, the data is also not being updated):
https://media.discordapp.net/attachments/1082470370902294600/1430685570035613707/image.png?ex=68faad44&is=68f95bc4&hm=4a4ca68cbcefacd403c967a31dac016564d6373b9e775063b1d92e65a07a1e2f&=&format=webp&quality=lossless&width=1232&height=693
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 4, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Copilot AI and others added 2 commits January 4, 2026 01:45
…ithout heightmap

- Clear cachedHeightmap, texHeightMap, and texShadowHeight when:
  - No worldspace is active
  - Current worldspace has no heightmap
  - Worldspace has interior-like flags (kNoSky or kFixedDimensions)
- Add debug UI info showing interior-like flag, cached heightmap, and ready state
- Prevents stale heightmap data from previous worldspace causing broken shadows in Markarth and similar locations

Co-authored-by: alandtse <7086117+alandtse@users.noreply.github.com>
Co-authored-by: alandtse <7086117+alandtse@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix terrain shadows breaking in Markarth fix(TerrainShadows): clear stale heightmap cache on worldspace transitions Jan 4, 2026
Copilot AI requested a review from alandtse January 4, 2026 01:46
@alandtse alandtse marked this pull request as ready for review January 4, 2026 02:14
Copilot AI review requested due to automatic review settings January 4, 2026 02:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes terrain shadow rendering artifacts in Markarth and similar worldspaces by clearing stale heightmap cache during worldspace transitions. Previously, the cache persisted when entering worldspaces without heightmaps or with interior-like characteristics, causing shadows to render with incorrect terrain data from previous worldspaces.

Key Changes:

  • Clear heightmap cache (cachedHeightmap, texHeightMap, texShadowHeight) when entering worldspaces without heightmaps or with interior-like flags (kNoSky, kFixedDimensions)
  • Add debug UI diagnostics showing interior-like flag status, cached heightmap worldspace, and heightmap ready state

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Features/TerrainShadows.cpp Added cache invalidation logic for worldspaces without heightmaps or with interior-like flags, and enhanced debug UI with additional diagnostic information
_codeql_detected_source_root CodeQL configuration file addition (not a functional code change)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 4, 2026

Using provided base ref: bb5615e
Using base ref: bb5615e
Base commit date: 2026-01-04T00:44:58Z (Sunday, January 04, 2026 12:44 AM)
No actionable suggestions for changed features.

Copy link
Copy Markdown
Collaborator

@alandtse alandtse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please verify the enum are valid via the commonlib submodule repo. Also, remove extraneous files and confirm that it builds

- Remove _codeql_detected_source_root symlink created during security scan
- Add _codeql_detected_source_root to .gitignore to prevent future commits

Co-authored-by: alandtse <7086117+alandtse@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 4, 2026

@copilot please verify the enum are valid via the commonlib submodule repo. Also, remove extraneous files and confirm that it builds

Verified enum values via CommonLibSSE-NG submodule:

  • RE::TESWorldSpace::Flag::kNoSky (bit 5) - confirmed at TESWorldSpace.h:133
  • RE::TESWorldSpace::Flag::kFixedDimensions (bit 6) - confirmed at TESWorldSpace.h:134

Usage pattern matches existing code in src/Utils/Game.cpp:308.

Removed _codeql_detected_source_root symlink and added to .gitignore (commit f818845).

Build verification requires Windows environment with Visual Studio. Code follows existing patterns and uses verified CommonLibSSE-NG APIs.

Copilot AI requested a review from alandtse January 4, 2026 02:24
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 4, 2026

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

@doodlum
Copy link
Copy Markdown
Collaborator

doodlum commented Jan 5, 2026

The issue is child worldspaces, not worldspaces pretending to be interiors. We should probably just close this.

@alandtse alandtse closed this Jan 5, 2026
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.

CS 1.4.6 Terrain shadows breaking in Markarth

4 participants