Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtext] Don't return default font if LoadFontEx fails #4077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Peter0x44
Copy link
Contributor

It is currently impossible to check a font loaded successfully with IsFontReady because LoadFontEx will always return a valid font.

DrawTextEx has this check:
if (font.texture.id == 0) font = GetFontDefault(); // Security check in case of not valid font

So anyone relying on the default font as a fallback for fonts failing to load should still be covered.

It is currently impossible to check a font loaded successfully with
IsFontReady because LoadFontEx will always return a valid font.

DrawTextEx has this check:
if (font.texture.id == 0) font = GetFontDefault();  // Security check in case of not valid font

So anyone relying on the default font as a fallback for fonts failing to
load should still be covered.
@CrackedPixel
Copy link
Sponsor Contributor

@Peter0x44 do you think something like this should be applied to loading shaders as well?

@raysan5
Copy link
Owner

raysan5 commented Jun 20, 2024

@Peter0x44 @CrackedPixel raylib has some fallbacks for convenience, change this behaviour could imply reviewing several assets loading functions... It's not a one-function trivial change.

@Peter0x44
Copy link
Contributor Author

Peter0x44 commented Jun 20, 2024

@raysan5 I think it is.
Both DrawTextEx and MeasureTextEx have checks for passing invalid fonts to them, and just use the default font instead.
Are there any others I need to be aware of?

@Peter0x44
Copy link
Contributor Author

About the shaders, I didn't think about reviewing them, but it can be done at a later time.
i believe this change is self-contained and should be okay.

@raysan5
Copy link
Owner

raysan5 commented Jun 24, 2024

Just for completion, here it is a list with the result of loading several types of assets (from files) and failing doing it:

  • Image: Returns invalid image, image.data = NULL
  • Texture2D: Returns invalid texture, texture.id = 0
  • Font: Fallback to GetFontDefault() --> Return invalid font -> Does it CRASH anything?
  • Mesh: Returns invalid vertex data, mesh.vertex = NULL, mesh.vaoId = 0
  • Shader: Fallback to default shader RLGL.State.defaultShaderId
  • Material: Fallback to LoadMaterialDefault()
  • Wave: Returns invalid wave, wave.data = NULL
  • Sound: Returns invalid sound, sounds.stream.buffer = NULL
  • Music: Returns invalid music, music.stream.buffer = NULL

@Peter0x44 Please, could you review if failing on font loading, with no fallback, any example crashes?

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.

None yet

3 participants