Skip to content

Commit 2a4cf2c

Browse files
committed
Fix shapes_colors_palette
- Asyncify requires `memcpy` / `memset` to copy arrays - somehow does not work - Make arrays static for now
1 parent 19e303a commit 2a4cf2c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

examples/shapes_colors_palette.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ int main(void)
2727

2828
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - colors palette");
2929

30-
Color colors[MAX_COLORS_COUNT] = {
30+
static Color colors[MAX_COLORS_COUNT] = {
3131
DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
3232
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
3333
GREEN, SKYBLUE, PURPLE, BEIGE };
3434

35-
const char *colorNames[MAX_COLORS_COUNT] = {
35+
static const char *colorNames[MAX_COLORS_COUNT] = {
3636
"DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE",
3737
"DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN",
3838
"LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" };
3939

40-
Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array
40+
static Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array
4141

4242
// Fills colorsRecs data (for every rectangle)
4343
for (int i = 0; i < MAX_COLORS_COUNT; i++)

raylib.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export default class RaylibJs {
118118
}
119119

120120
async WindowShouldClose() {
121-
console.log("before frame");
122121
let timestamp = await nextFrame();
123-
console.log("after frame");
124122
if (this.previous === undefined) {
125123
this.previous = timestamp;
126124
timestamp = await nextFrame();
@@ -261,6 +259,20 @@ export default class RaylibJs {
261259
this.ctx.font = `${fontSize}px grixel`;
262260
return this.ctx.measureText(text).width;
263261
}
262+
263+
memcpy(dest_ptr, src_ptr, count) {
264+
const buffer = this.wasm.instance.exports.memory.buffer;
265+
// TODO: Why this does not fix asyncify problems
266+
new Uint8Array(buffer, dest_ptr, count)
267+
.set(new Uint8Array(buffer, src_ptr, count));
268+
return dest_ptr;
269+
}
270+
271+
memset(ptr, value, num) {
272+
const buffer = this.wasm.instance.exports.memory.buffer;
273+
new Int32Array(buffer, ptr, num).fill(value);
274+
return ptr;
275+
}
264276
}
265277

266278
const glfwKeyMapping = {

wasm/shapes_colors_palette.wasm

-1.01 KB
Binary file not shown.

0 commit comments

Comments
 (0)