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

Add Font::null() static constructor #1208

Merged
merged 3 commits into from
Feb 10, 2025
Merged

Add Font::null() static constructor #1208

merged 3 commits into from
Feb 10, 2025

Conversation

DanRStevens
Copy link
Collaborator

This helps with writing test code for the Font class, and serves as a useful fallback instance.

By having a null instance, we can pass around a valid object to API calls expecting a Font instance, without fear of memory errors, or having to worry about putting guards around uses of Font.

Related:

Despite documentation stating that `glDeleteTextures` can safely handle being passed `0` and will ignore them, that doesn't seem to be the case on MacOS. Passing in a `0` on MacOS leads to a segmentation fault.

In order to support a `null` `Font` object, we need to be able to pass `0` to `glDeleteTextures`.

Documentation:
https://registry.khronos.org/OpenGL-Refpages/es2.0/xhtml/glDeleteTextures.xml
A `null` `Font` object can be useful as a placeholder and for testing. Such a font would have nothing loaded, and could not print any text. It would however be usable as a `Font` object, and would be safe to call member functions on, without resulting in a crash or memory problem.

Here a named `static` constructor was chosen to make it obvious such an object was being created. By keeping the default construtor `protected`, we prevent accidentally creating `null` `Font` objects.
@DanRStevens DanRStevens merged commit b8664e7 into main Feb 10, 2025
8 checks passed
@DanRStevens DanRStevens deleted the addFontNull branch February 10, 2025 21:16
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.

1 participant