4 Commits

Author SHA1 Message Date
9056ea3299 [examples] core_input_gestures_testbed: fix out-of-bounds log read (#6238)
gestureLogIndex started at GESTURE_LOG_SIZE, and the log drawing loop
starts reading at that index, so gestureLog[GESTURE_LOG_SIZE] (one past
the end) was read every frame until the first gesture was logged.
Start the index at 0 instead. Logging is unchanged: the first logged
gesture still wraps to GESTURE_LOG_SIZE - 1.
2026-10-09 00:57:48 +02:00
806d68a9bc [examples] audio_stream_callback: fix out-of-bounds read in waveform drawing (#6237)
The waveform loop draws a line from sample i to sample i + 1 for every
x in [0, screenWidth). For the last x, the end point index works out to
SAMPLE_RATE, one past the end of buffer[SAMPLE_RATE]. Stop the loop one
pixel earlier so the last segment ends on the final sample.
2026-10-09 00:56:35 +02:00
3825bbf2d4 [raudio] LoadSoundAlias(): check source buffer before use (#6236)
If the source sound failed to load (for example when no audio
playback device could be initialized), its stream.buffer is NULL and
LoadSoundAlias() dereferenced it. Check the buffer first, like
UnloadSoundAlias() and IsSoundValid() already do, so an empty Sound
is returned instead of crashing.

Seen with examples/audio/audio_sound_multi (reported in #5664).
2026-10-09 00:55:47 +02:00
c8b19b297b [rmodels] Fix GetRayCollisionSphere() hitting spheres behind the ray (#6231)
* [rmodels] Fix GetRayCollisionSphere() hitting spheres behind the ray

* Return zeroed struct on failure cases
2026-10-09 00:53:32 +02:00
4 changed files with 36 additions and 22 deletions

View File

@ -131,7 +131,7 @@ int main(void)
DrawText("Left/right to change wave type", 10, 30, 20, DARKGRAY);
// Draw the last 10 ms of uploaded audio
for (int i = 0; i < screenWidth; i++)
for (int i = 0; i < screenWidth - 1; i++)
{
Vector2 startPos = {(float)i, 250 - 50*buffer[SAMPLE_RATE - SAMPLE_RATE/100 + i*SAMPLE_RATE/100/screenWidth] };
Vector2 endPos = { (float)(i + 1), 250 - 50*buffer[SAMPLE_RATE - SAMPLE_RATE/100 + (i + 1)*SAMPLE_RATE/100/screenWidth] };

View File

@ -50,7 +50,7 @@ int main(void)
// NOTE: The gesture log uses an array (as an inverted circular queue) to store the performed gestures
char gestureLog[GESTURE_LOG_SIZE][12] = { "" };
// NOTE: The index for the inverted circular queue (moving from last to first direction, then looping around)
int gestureLogIndex = GESTURE_LOG_SIZE;
int gestureLogIndex = 0;
int previousGesture = 0;
// Log mode values:

View File

@ -988,7 +988,7 @@ Sound LoadSoundAlias(Sound source)
{
Sound sound = { 0 };
if (source.stream.buffer->data != NULL)
if ((source.stream.buffer != NULL) && (source.stream.buffer->data != NULL))
{
AudioBuffer *audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, 0, AUDIO_BUFFER_USAGE_STATIC);

View File

@ -4174,31 +4174,45 @@ RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius)
Vector3 raySpherePos = Vector3Subtract(center, ray.position);
float vector = Vector3DotProduct(raySpherePos, ray.direction);
float distance = Vector3Length(raySpherePos);
float d = radius*radius - (distance*distance - vector*vector);
float distanceToCenter = Vector3Length(raySpherePos);
float d = radius*radius - (distanceToCenter*distanceToCenter - vector*vector);
collision.hit = d >= 0.0f;
// Check if ray origin is inside the sphere to calculate the correct collision point
if (distance < radius)
// Check if the ray's line intersects with the sphere
if (d >= 0.0f)
{
collision.distance = vector + sqrtf(d);
Vector3 point = { 0 };
Vector3 normal = { 0 };
float hitDistance = 0.0f;
// Calculate collision point
collision.point = Vector3Add(ray.position, Vector3Scale(ray.direction, collision.distance));
// Check if ray origin is inside the sphere to calculate the correct collision point
if (distanceToCenter < radius)
{
hitDistance = vector + sqrtf(d);
// Calculate collision normal (pointing outwards)
collision.normal = Vector3Negate(Vector3Normalize(Vector3Subtract(collision.point, center)));
}
else
{
collision.distance = vector - sqrtf(d);
// Calculate collision point
point = Vector3Add(ray.position, Vector3Scale(ray.direction, hitDistance));
// Calculate collision point
collision.point = Vector3Add(ray.position, Vector3Scale(ray.direction, collision.distance));
// Calculate collision normal (pointing outwards)
normal = Vector3Negate(Vector3Normalize(Vector3Subtract(point, center)));
}
else
{
hitDistance = vector - sqrtf(d);
// Calculate collision normal (pointing inwards)
collision.normal = Vector3Normalize(Vector3Subtract(collision.point, center));
// Calculate collision point
point = Vector3Add(ray.position, Vector3Scale(ray.direction, hitDistance));
// Calculate collision normal (pointing inwards)
normal = Vector3Normalize(Vector3Subtract(point, center));
}
if (hitDistance >= 0.0f)
{
collision.hit = true;
collision.point = point;
collision.normal = normal;
collision.distance = hitDistance;
}
}
return collision;