summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-03-07 20:33:45 +0100
committerRay <[email protected]>2023-03-07 20:33:45 +0100
commitab1e246367973c4d2ef74843a5f9588010889466 (patch)
tree49a68799e9883b269c869cfcc7d9483aeec3a43a /src
parent15716e59dc1fddbf6efce18a359448fe6d53a908 (diff)
downloadraylib-ab1e246367973c4d2ef74843a5f9588010889466.tar.gz
raylib-ab1e246367973c4d2ef74843a5f9588010889466.zip
REVIEWED: Data types validation
Diffstat (limited to 'src')
-rw-r--r--src/raudio.c10
-rw-r--r--src/rmodels.c11
-rw-r--r--src/rtext.c9
-rw-r--r--src/rtextures.c4
4 files changed, 25 insertions, 9 deletions
diff --git a/src/raudio.c b/src/raudio.c
index 8ac09b2f..4bdbede9 100644
--- a/src/raudio.c
+++ b/src/raudio.c
@@ -912,11 +912,11 @@ Sound LoadSoundFromWave(Wave wave)
// Checks if a sound is ready
bool IsSoundReady(Sound sound)
{
- return ((sound.frameCount > 0) && // Validate frame count
- (sound.stream.buffer != NULL) && // Validate stream buffer
- (sound.stream.sampleRate > 0) && // Validate sample rate is supported
- (sound.stream.sampleSize > 0) && // Validate sample size is supported
- (sound.stream.channels > 0)); // Validate number of channels supported
+ return ((sound.frameCount > 0) && // Validate frame count
+ (sound.stream.buffer != NULL) && // Validate stream buffer
+ (sound.stream.sampleRate > 0) && // Validate sample rate is supported
+ (sound.stream.sampleSize > 0) && // Validate sample size is supported
+ (sound.stream.channels > 0)); // Validate number of channels supported
}
// Unload wave data
diff --git a/src/rmodels.c b/src/rmodels.c
index b28e14dc..a2b5dd88 100644
--- a/src/rmodels.c
+++ b/src/rmodels.c
@@ -1112,7 +1112,13 @@ Model LoadModelFromMesh(Mesh mesh)
// Check if a model is ready
bool IsModelReady(Model model)
{
- return model.meshes != NULL && model.materials != NULL && model.meshMaterial != NULL && model.meshCount > 0 && model.materialCount > 0;
+ return ((model.meshes != NULL) && // Validate model contains some mesh
+ (model.materials != NULL) && // Validate model contains some material (at least default one)
+ (model.meshMaterial != NULL) && // Validate mesh-material linkage
+ (model.meshCount > 0) && // Validate mesh count
+ (model.materialCount > 0)); // Validate material count
+
+ // NOTE: This is a very general model validation, many elements could be validated from a model...
}
// Unload model (meshes/materials) from memory (RAM and/or VRAM)
@@ -1959,7 +1965,8 @@ Material LoadMaterialDefault(void)
// Check if a material is ready
bool IsMaterialReady(Material material)
{
- return material.maps != NULL;
+ return ((material.maps != NULL) && // Validate material contain some map
+ (material.shader.id > 0)); // Validate material shader is valid
}
// Unload material from memory
diff --git a/src/rtext.c b/src/rtext.c
index f0726112..2d47bdf6 100644
--- a/src/rtext.c
+++ b/src/rtext.c
@@ -538,7 +538,14 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
// Check if a font is ready
bool IsFontReady(Font font)
{
- return font.glyphs != NULL;
+ return ((font.texture.id > 0) && // Validate OpenGL id fot font texture atlas
+ (font.baseSize > 0) && // Validate font size
+ (font.glyphCount > 0) && // Validate font contains some glyph
+ (font.recs != NULL) && // Validate font recs defining glyphs on texture atlas
+ (font.glyphs != NULL)); // Validate glyph data is loaded
+
+ // NOTE: Further validations could be done to verify if recs count and glyphs count
+ // match glyphCount and to verify that data contained is valid (glyphs values, metrics...)
}
// Load font data for further use
diff --git a/src/rtextures.c b/src/rtextures.c
index 56b200ce..12bca8a8 100644
--- a/src/rtextures.c
+++ b/src/rtextures.c
@@ -3362,7 +3362,9 @@ void UnloadTexture(Texture2D texture)
// Check if a render texture is ready
bool IsRenderTextureReady(RenderTexture2D target)
{
- return target.id > 0 && IsTextureReady(target.depth) && IsTextureReady(target.texture);
+ return ((target.id > 0) && // Validate OpenGL id
+ IsTextureReady(target.depth) && // Validate FBO depth texture/renderbuffer
+ IsTextureReady(target.texture)); // Validate FBO texture
}
// Unload render texture from GPU memory (VRAM)