Skip to content

bugfix(w3d): Fix leaked surface copy in screenshot and movie capture - #3477

Merged
xezon merged 2 commits into
TheSuperHackers:mainfrom
tintinhamans:arctic/fix/screenshot-surface-leak
Oct 12, 2026
Merged

xezon merged 2 commits into
TheSuperHackers:mainfrom
tintinhamans:arctic/fix/screenshot-surface-leak

Conversation

@tintinhamans

@tintinhamans tintinhamans commented Oct 11, 2026 •

Copy link
Copy Markdown

_Create_DX8_Surface returns a surface that already holds one reference. The screenshot code wraps it with the SurfaceClass(IDirect3DSurface8*) constructor, which goes through Attach and takes a second one. ~SurfaceClass releases one, so the image surface is never freed.

That is one back buffer sized system memory surface per screenshot, about 8 MB at 1080p and 33 MB at 4K. Update_Movie_Capture does it once per captured frame.

The copy is now built with SurfaceClass(width, height, format), which creates the surface itself and owns the only reference. Same CreateImageSurface, same blit from the back buffer, same lock on the system memory copy, so the GPU side is still never locked. _Get_DX8_Back_Buffer already does the equivalent by releasing the raw pointer right after wrapping it.

Applies to W3D_TakeCompressedScreenshot, WW3D::Make_Screen_Shot and WW3D::Update_Movie_Capture.

Found while auditing for memory leaks with the debug memory pool report.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9c575f3c-7c8d-4a6a-81ae-5d5a486d605c


📥 Commits

Reviewing files that changed from the base of the PR and between 43a4a16 and b2696d5.



📒 Files selected for processing (1)
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/stb_image_write_impl.cpp


🚧 Files skipped from review as they are similar to previous changes (1)
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/stb_image_write_impl.cpp


Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.




Walkthrough

Three screenshot and movie-capture paths now construct copied surfaces directly with SurfaceClass instead of using DX8Wrapper::_Create_DX8_Surface. Subsequent copy and capture processing remains unchanged. Copyright notices and the game title are updated.

Changes

Screenshot and movie-capture surfaces

Layer / File(s) Summary
Direct construction of copied surfaces
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp, Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DScreenshot.h, Core/GameEngineDevice/Source/W3DDevice/GameClient/stb_image_write_impl.cpp, Core/Libraries/Source/WWVegas/WW3D2/ww3d.cpp
Three screenshot and movie-capture paths construct copied surfaces directly with SurfaceClass. The subsequent copy and capture processing remain unchanged. Copyright years change to 2026, and the image-writing file header identifies Generals Zero Hour.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Suggested reviewers: caball009

Merge Risk: ⚪ Minimal · up to b2696

This update only changes a file header comment and has no runtime effect. The screenshot surface-leak fix described in the PR was not examined here beyond its description. No merge-blocking risk is evident.

Pre-merge checks | Passed 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the primary change: fixing a leaked surface copy in screenshot and movie capture.
Description check Passed The description directly explains the surface reference leak, the affected functions, the fix, and the related copyright updates.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the new constructor removes the extra reference without changing how capture reads the pixels.

Summary

Fixes the leaked surface copy in screenshot and movie capture.

  • Screenshot and movie captures now release each copied surface.
  • Three source headers now show updated project credits.

Reviews (3) · Last reviewed commit: "chore(screenshot): Update copyright head..." · Reviewed by Greptile

@Mauller Mauller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Putting tape on those leaks

@Caball009 Caball009 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This might seem like an odd request, but could you update these 3 files? #3387
Otherwise it might be a while before there's another somewhat related change.

This is desired copyright text (note Zero Hour & 2026):

**	Command & Conquer Generals Zero Hour(tm)
**	Copyright 2026 TheSuperHackers

Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DScreenshot.cpp Outdated
@tintinhamans
tintinhamans force-pushed the arctic/fix/screenshot-surface-leak branch from 36bd02c to 43a4a16 Compare October 11, 2026 21:57
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/stb_image_write_impl.cpp Outdated
@tintinhamans
tintinhamans force-pushed the arctic/fix/screenshot-surface-leak branch from 43a4a16 to b2696d5 Compare October 11, 2026 22:03
@Caball009 Caball009 added Bug Something is not working right, typically is user facing ThisProject The issue was introduced by this project, or this task is specific to this project Memory Is memory related Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour labels Oct 11, 2026

@Caball009 Caball009 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I can reproduce the leak with the main branch, and can confirm that these changes fix the leak. The resulting screenshots look as I'd expect at a quick glance. I did not check if the leak is indicative of a larger issue that requires more changes.

Looks ok to me.

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very good

@xezon xezon removed the ThisProject The issue was introduced by this project, or this task is specific to this project label Oct 12, 2026
@xezon
xezon merged commit fb2e2f0 into TheSuperHackers:main Oct 12, 2026
25 checks passed
@Caball009

Copy link
Copy Markdown

Retail doesn't have this bug, so we must have introduced it, presumably in #1785.

@xezon

xezon commented Oct 12, 2026

Copy link
Copy Markdown

Retail has the bug in unused functionality I think. Not in the removed BMP screenshot however. It's part retail, part our.

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

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker Memory Is memory related ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants