Skip to content

Commit e909f91

Browse files
csmartdaltoncsmartdalton
csmartdalton
andcommitted
Fix a regression in WASM image meshes
WASM uses float arrays for vertex and uv data, as opposed to 'Vec2D' arrays. Convert vertexCount to an 'f32Count', which is vertexCount * 2. Diffs= df9c651a1 Fix a regression in WASM image meshes (#5950) Co-authored-by: Chris Dalton <[email protected]>
1 parent 541fd78 commit e909f91

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

.rive_head

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
853ae7de1d020bc13e84359f816215764923215c
1+
df9c651a1cf45ef795de0b7242156e290a4cf499

wasm/premake5.lua

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ includedirs {
1818
harfbuzz .. '/src',
1919
sheenbidi .. '/Headers'
2020
}
21+
flags {
22+
'FatalCompileWarnings',
23+
}
2124

2225
files {
2326
source .. '/src/**.cpp',

wasm/src/bindings_c2d.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,25 @@ class RendererWrapper : public wrapper<rive::Renderer>
119119
auto uv = rive::DataRenderBuffer::Cast(uvCoords_f32.get());
120120
auto indices = rive::DataRenderBuffer::Cast(indices_u16.get());
121121

122-
assert(vtx->sizeInBytes() == vertexCount * sizeof(Vec2D));
123-
assert(uv->sizeInBytes() == vertexCount * sizeof(Vec2D));
122+
uint32_t f32Count = vertexCount * 2;
123+
assert(vtx->sizeInBytes() == f32Count * sizeof(float));
124+
assert(uv->sizeInBytes() == f32Count * sizeof(float));
124125
assert(indices->sizeInBytes() == indexCount * sizeof(uint16_t));
125126

126-
if (vertexCount == 0 || indexCount == 0)
127+
if (f32Count == 0 || indexCount == 0)
127128
{
128129
return;
129130
}
130131

131-
emscripten::val uvJS{emscripten::typed_memory_view(vertexCount, uv->f32s())};
132-
emscripten::val vtxJS{emscripten::typed_memory_view(vertexCount, vtx->f32s())};
132+
emscripten::val uvJS{emscripten::typed_memory_view(f32Count, uv->f32s())};
133+
emscripten::val vtxJS{emscripten::typed_memory_view(f32Count, vtx->f32s())};
133134
emscripten::val indicesJS{emscripten::typed_memory_view(indexCount, indices->u16s())};
134135

135136
// Compute the mesh's bounding box.
136137
float m[6];
137138
emscripten::val mJS{emscripten::typed_memory_view(6, m)};
138139
call<void>("_getMatrix", mJS);
139-
auto [l, t, r, b] = bbox(m, vtx->f32s(), vertexCount);
140+
auto [l, t, r, b] = bbox(m, vtx->f32s(), f32Count);
140141

141142
call<void>("_drawImageMesh", image, value, opacity, vtxJS, uvJS, indicesJS, l, t, r, b);
142143
}
@@ -301,7 +302,7 @@ class C2DFactory : public Factory
301302
{
302303
rcp<RenderBuffer> makeRenderBuffer(RenderBufferType type,
303304
RenderBufferFlags flags,
304-
size_t sizeInBytes)
305+
size_t sizeInBytes) override
305306
{
306307
return make_rcp<DataRenderBuffer>(type, flags, sizeInBytes);
307308
}

0 commit comments

Comments
 (0)