Skip to content

Conversation

@hollasch
Copy link
Collaborator

The linear floating-point image data stored in the rtw_image::fdata member variable had a lifetime from image load to the class destruction. We don't need the original floating-point data after the image has been loaded.

This change moves the floating-point data buffer inside the load() function. It is released before the load function returns.

Resolves #1723

The linear floating-point image data stored in the `rtw_image::fdata`
member variable had a lifetime from image load to the class destruction.
We don't need the original floating-point data after the image has been
loaded.

This change moves the floating-point data buffer inside the load()
function. It is released before the load function returns.

Resolves #1723
@hollasch hollasch added this to the v4.1.0 milestone Dec 31, 2025
@hollasch hollasch requested review from a team and Copilot December 31, 2025 23:24
@hollasch hollasch self-assigned this Dec 31, 2025
Copy link

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 refactors the rtw_image class to improve memory efficiency by reducing the lifetime of the floating-point image data buffer. The fdata member variable is converted from a class-level member to a local variable within the load() function, which is freed immediately after the byte conversion is complete rather than persisting until object destruction.

Key changes:

  • Moved fdata from class member to local variable in load() function
  • Updated convert_to_bytes() to accept fdata as a parameter instead of accessing it as a member
  • Simplified width() and height() methods by removing the fdata == nullptr check

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/TheRestOfYourLife/rtw_stb_image.h Refactored rtw_image class to scope fdata locally within load(), eliminating class member and updating related methods
src/TheNextWeek/rtw_stb_image.h Applied identical refactoring to scope fdata locally within load(), matching changes in TheRestOfYourLife version
books/RayTracingTheNextWeek.html Updated documentation to reflect the code changes in rtw_image class
CHANGELOG.md Added entry for the fdata lifetime improvement and standardized terminology in v4.0.2 section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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