Pointer Parameters #21427
-
Hi, I exported this function out: // Set background color (framebuffer clear color)
void ClearBackground(Color color)
{
rlClearColor(color.r, color.g, color.b, color.a);
rlClearScreenBuffers();
} The structure of the received parameter: // Color, 4 components, R8G8B8A8 (32bit)
typedef struct Color {
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
} Color; This way I can adjust the color: const ClearBackground = ({ r = 0, g = 0, b = 0, a = 0 }) => {
const address = rl._malloc(4);
/*rl.HEAPU8[address] = r;
rl.HEAPU8[address + 1] = g;
rl.HEAPU8[address + 2] = b;
rl.HEAPU8[address + 3] = a;*/
rl.HEAPU8.set([r, g, b, a], address);
rl._ClearBackground(address);
}; But can't I do it another way? // Something like:
rl._ClearBackground(new Uint8Array([255, 255, 255, 255])); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If void ClearBackground(unsigned char r, unsigned char g, unsigned char b, unsigned char a); |
Beta Was this translation helpful? Give feedback.
If
Color
is a struct then clang will use an allocated area in memory, so you do need to malloc as you do here (and free, as nothing else knows you allocated it). Another option is to allocate on the stack (stackAlloc
) if you know it is small. However, most people change their API to avoid passing structs, and leave only simple types on the boundary, like this: