Skip to content

Commit a92f67b

Browse files
authored
Merge pull request #5031 from AmityWilder/safety-comments
Safety Comments for Sound/Texture Update Functions
2 parents 7f8dfc6 + 205b6a0 commit a92f67b

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

parser/output/raylib_api.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8529,7 +8529,7 @@
85298529
},
85308530
{
85318531
"name": "UpdateTexture",
8532-
"description": "Update GPU texture with new data",
8532+
"description": "Update GPU texture with new data (pixels should be able to fill texture)",
85338533
"returnType": "void",
85348534
"params": [
85358535
{
@@ -8544,7 +8544,7 @@
85448544
},
85458545
{
85468546
"name": "UpdateTextureRec",
8547-
"description": "Update GPU texture rectangle with new data",
8547+
"description": "Update GPU texture rectangle with new data (pixels and rec should fit in texture)",
85488548
"returnType": "void",
85498549
"params": [
85508550
{
@@ -11511,7 +11511,7 @@
1151111511
},
1151211512
{
1151311513
"name": "UpdateSound",
11514-
"description": "Update sound buffer with new data",
11514+
"description": "Update sound buffer with new data (data and frame count should fit in sound)",
1151511515
"returnType": "void",
1151611516
"params": [
1151711517
{

parser/output/raylib_api.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,7 +6264,7 @@ return {
62646264
},
62656265
{
62666266
name = "UpdateTexture",
6267-
description = "Update GPU texture with new data",
6267+
description = "Update GPU texture with new data (pixels should be able to fill texture)",
62686268
returnType = "void",
62696269
params = {
62706270
{type = "Texture2D", name = "texture"},
@@ -6273,7 +6273,7 @@ return {
62736273
},
62746274
{
62756275
name = "UpdateTextureRec",
6276-
description = "Update GPU texture rectangle with new data",
6276+
description = "Update GPU texture rectangle with new data (pixels and rec should fit in texture)",
62776277
returnType = "void",
62786278
params = {
62796279
{type = "Texture2D", name = "texture"},
@@ -7872,7 +7872,7 @@ return {
78727872
},
78737873
{
78747874
name = "UpdateSound",
7875-
description = "Update sound buffer with new data",
7875+
description = "Update sound buffer with new data (data and frame count should fit in sound)",
78767876
returnType = "void",
78777877
params = {
78787878
{type = "Sound", name = "sound"},

parser/output/raylib_api.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,13 +3271,13 @@ Function 364: UnloadRenderTexture() (1 input parameters)
32713271
Function 365: UpdateTexture() (2 input parameters)
32723272
Name: UpdateTexture
32733273
Return type: void
3274-
Description: Update GPU texture with new data
3274+
Description: Update GPU texture with new data (pixels should be able to fill texture)
32753275
Param[1]: texture (type: Texture2D)
32763276
Param[2]: pixels (type: const void *)
32773277
Function 366: UpdateTextureRec() (3 input parameters)
32783278
Name: UpdateTextureRec
32793279
Return type: void
3280-
Description: Update GPU texture rectangle with new data
3280+
Description: Update GPU texture rectangle with new data (pixels and rec should fit in texture)
32813281
Param[1]: texture (type: Texture2D)
32823282
Param[2]: rec (type: Rectangle)
32833283
Param[3]: pixels (type: const void *)
@@ -4399,7 +4399,7 @@ Function 530: IsSoundValid() (1 input parameters)
43994399
Function 531: UpdateSound() (3 input parameters)
44004400
Name: UpdateSound
44014401
Return type: void
4402-
Description: Update sound buffer with new data
4402+
Description: Update sound buffer with new data (data and frame count should fit in sound)
44034403
Param[1]: sound (type: Sound)
44044404
Param[2]: data (type: const void *)
44054405
Param[3]: sampleCount (type: int)

parser/output/raylib_api.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,11 +2150,11 @@
21502150
<Function name="UnloadRenderTexture" retType="void" paramCount="1" desc="Unload render texture from GPU memory (VRAM)">
21512151
<Param type="RenderTexture2D" name="target" desc="" />
21522152
</Function>
2153-
<Function name="UpdateTexture" retType="void" paramCount="2" desc="Update GPU texture with new data">
2153+
<Function name="UpdateTexture" retType="void" paramCount="2" desc="Update GPU texture with new data (pixels should be able to fill texture)">
21542154
<Param type="Texture2D" name="texture" desc="" />
21552155
<Param type="const void *" name="pixels" desc="" />
21562156
</Function>
2157-
<Function name="UpdateTextureRec" retType="void" paramCount="3" desc="Update GPU texture rectangle with new data">
2157+
<Function name="UpdateTextureRec" retType="void" paramCount="3" desc="Update GPU texture rectangle with new data (pixels and rec should fit in texture)">
21582158
<Param type="Texture2D" name="texture" desc="" />
21592159
<Param type="Rectangle" name="rec" desc="" />
21602160
<Param type="const void *" name="pixels" desc="" />
@@ -2940,7 +2940,7 @@
29402940
<Function name="IsSoundValid" retType="bool" paramCount="1" desc="Checks if a sound is valid (data loaded and buffers initialized)">
29412941
<Param type="Sound" name="sound" desc="" />
29422942
</Function>
2943-
<Function name="UpdateSound" retType="void" paramCount="3" desc="Update sound buffer with new data">
2943+
<Function name="UpdateSound" retType="void" paramCount="3" desc="Update sound buffer with new data (data and frame count should fit in sound)">
29442944
<Param type="Sound" name="sound" desc="" />
29452945
<Param type="const void *" name="data" desc="" />
29462946
<Param type="int" name="sampleCount" desc="" />

src/raudio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,8 @@ void UnloadSoundAlias(Sound alias)
10371037
}
10381038

10391039
// Update sound buffer with new data
1040+
// NOTE 1: data format must match sound.stream.sampleSize
1041+
// NOTE 2: frameCount must not exceed sound.frameCount
10401042
void UpdateSound(Sound sound, const void *data, int frameCount)
10411043
{
10421044
if (sound.stream.buffer != NULL)

src/raylib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,8 @@ RLAPI bool IsTextureValid(Texture2D texture);
14241424
RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory (VRAM)
14251425
RLAPI bool IsRenderTextureValid(RenderTexture2D target); // Check if a render texture is valid (loaded in GPU)
14261426
RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM)
1427-
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
1428-
RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data
1427+
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data (pixels should be able to fill texture)
1428+
RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data (pixels and rec should fit in texture)
14291429

14301430
// Texture configuration functions
14311431
RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture
@@ -1646,7 +1646,7 @@ RLAPI Sound LoadSound(const char *fileName); // Load so
16461646
RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
16471647
RLAPI Sound LoadSoundAlias(Sound source); // Create a new sound that shares the same sample data as the source sound, does not own the sound data
16481648
RLAPI bool IsSoundValid(Sound sound); // Checks if a sound is valid (data loaded and buffers initialized)
1649-
RLAPI void UpdateSound(Sound sound, const void *data, int sampleCount); // Update sound buffer with new data
1649+
RLAPI void UpdateSound(Sound sound, const void *data, int sampleCount); // Update sound buffer with new data (data and frame count should fit in sound)
16501650
RLAPI void UnloadWave(Wave wave); // Unload wave data
16511651
RLAPI void UnloadSound(Sound sound); // Unload sound
16521652
RLAPI void UnloadSoundAlias(Sound alias); // Unload a sound alias (does not deallocate sample data)

src/rtextures.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,14 +4338,17 @@ void UnloadRenderTexture(RenderTexture2D target)
43384338
}
43394339

43404340
// Update GPU texture with new data
4341-
// NOTE: pixels data must match texture.format
4341+
// NOTE 1: pixels data must match texture.format
4342+
// NOTE 2: pixels data must contain at least as many pixels as texture
43424343
void UpdateTexture(Texture2D texture, const void *pixels)
43434344
{
43444345
rlUpdateTexture(texture.id, 0, 0, texture.width, texture.height, texture.format, pixels);
43454346
}
43464347

43474348
// Update GPU texture rectangle with new data
4348-
// NOTE: pixels data must match texture.format
4349+
// NOTE 1: pixels data must match texture.format
4350+
// NOTE 2: pixels data must contain as many pixels as rec contains
4351+
// NOTE 3: rec must fit completely within texture's width and height
43494352
void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels)
43504353
{
43514354
rlUpdateTexture(texture.id, (int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, texture.format, pixels);

0 commit comments

Comments
 (0)