We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4847 - TTF_Font from SDL_RWops requires keeping RWops open
Summary: TTF_Font from SDL_RWops requires keeping RWops open
Status: RESOLVED FIXED
Alias: None
Product: SDL_ttf
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-29 17:49 UTC by Michael Rittenhouse
Modified: 2019-10-30 12:42 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rittenhouse 2019-10-29 17:49:10 UTC
Overview:

Unlike SDL_image which copies raw image data from an SDL_RWops into the resultant SDL_Surface or SDL_Texture, opening a TTF_Font from an SDL_RWops does not make any copy of the data. This means that the SDL_RWops must be kept alive for the lifetime of the TTF_Font. In the case of SDL_ttf, this behavior makes sense, but does not appear to be documented anywhere (namely [https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html]).

Attempting to use this TTF_Font after the SDL_RWops has been closed may result in a segfault or other unexpected behavior.



Expected Results:

The behavior should be documented that opening a TTF_Font from an SDL_RWops requires the SDL_RWops to be kept alive for the lifetime of the TTF_Font. Inspection of the source should not be necessary to understand this requirement.



Build Date & Hardware: (N/A)



Additional Builds and Platforms: (N/A)



Additional Information:

Related issue reported at [https://github.com/andelf/rust-sdl2_ttf/issues/29], which begins with, "As far as I understand RWops must outlive Font, since C library uses them after font is created." Clearly the requirement is not well established by the current documentation.
Comment 1 Sylvain 2019-10-30 12:42:42 UTC
This is true, thanks !
I've added this in the header https://hg.libsdl.org/SDL_ttf/rev/2ff567b9bd42