Error check using IsValid functions and return error unions (#191)

* Verify shaders are valid

* Verify images are valid

* Verify models are valid

* Verify materials are valid

* Verify textures are valid

* Verify render textures are valid

* Verify waves are valid

* Verify sounds are valid

* Verify music is valid

* Verify audio streams are valid

* Verify fonts are valid

* Update examples to handle error unions
This commit is contained in:
vent 2025-01-11 17:07:33 +00:00 committed by GitHub
parent 30ce68004f
commit 41022159ad
Failed to generate hash of commit
8 changed files with 475 additions and 188 deletions

View file

@ -41,7 +41,7 @@ pub fn main() anyerror!void {
rl.setAudioStreamBufferSizeDefault(MAX_SAMPLES_PER_UPDATE);
// Init raw audio stream (sample rate: 44100, sample size: 16bit-short, channels: 1-mono)
const stream = rl.loadAudioStream(44100, 16, 1);
const stream = try rl.loadAudioStream(44100, 16, 1);
defer rl.unloadAudioStream(stream); // Close raw audio stream and delete buffers from RAM
rl.setAudioStreamCallback(stream, &audioInputCallback);

View file

@ -15,10 +15,10 @@ pub fn main() anyerror!void {
rl.initWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
defer rl.closeWindow(); // Close window and OpenGL context
const texture: rl.Texture = rl.Texture.init("resources/textures/fudesumi.png");
const texture: rl.Texture = try rl.Texture.init("resources/textures/fudesumi.png");
defer rl.unloadTexture(texture);
const shdrOutline: rl.Shader = rl.loadShader(null, "resources/shaders/glsl330/outline.fs");
const shdrOutline: rl.Shader = try rl.loadShader(null, "resources/shaders/glsl330/outline.fs");
defer rl.unloadShader(shdrOutline);
var outlineSize: f32 = 2.0;

View file

@ -17,7 +17,7 @@ pub fn main() anyerror!void {
defer rl.closeWindow(); // Close window and OpenGL context
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
const scarfy: rl.Texture = rl.Texture.init("resources/textures/scarfy.png"); // Texture loading
const scarfy: rl.Texture = try rl.Texture.init("resources/textures/scarfy.png"); // Texture loading
defer rl.unloadTexture(scarfy); // Texture unloading
const position = rl.Vector2.init(350.0, 280.0);

View file

@ -20,9 +20,9 @@ pub fn main() anyerror!void {
// NOTE: Be careful, background width must be equal or bigger than screen width
// if not, texture should be draw more than two times for scrolling effect
const background = rl.loadTexture("resources/textures/cyberpunk_street_background.png");
const midground = rl.loadTexture("resources/textures/cyberpunk_street_midground.png");
const foreground = rl.loadTexture("resources/textures/cyberpunk_street_foreground.png");
const background = try rl.loadTexture("resources/textures/cyberpunk_street_background.png");
const midground = try rl.loadTexture("resources/textures/cyberpunk_street_midground.png");
const foreground = try rl.loadTexture("resources/textures/cyberpunk_street_foreground.png");
defer rl.unloadTexture(background); // Unload background texture
defer rl.unloadTexture(midground); // Unload midground texture
defer rl.unloadTexture(foreground); // Unload foreground texture

View file

@ -25,8 +25,8 @@ pub fn main() anyerror!void {
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
const image = rl.loadImage("logo/logo.png"); // Loaded in CPU memory (RAM)
const texture = rl.loadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
const image = try rl.loadImage("logo/logo.png"); // Loaded in CPU memory (RAM)
const texture = try rl.loadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
// Once image has been converted to texture and uploaded to VRAM,
// it can be unloaded from RAM
rl.unloadImage(image);