Repository navigation
Description
Submission checklist
- I have confirmed the issue is present in the latest version of the
riveFlutter package - I have searched the documentation and forums and could not find an answer
- I have searched existing issues and this is not a duplicate
Reproduced on rive 0.15.0-dev.4 / rive_native 0.2.0-dev.4. For 0.15.0-dev.5 / 0.2.0-dev.5 I only checked the source: sniffImageSize is unchanged there, so I expect the same result, but I have not run it.
Description
With Factory.rive, a .riv whose embedded images are KTX2 (ASTC) uploads and samples correctly, and GPU memory drops as expected, but every image that is not a mesh is drawn at the wrong position. Each one is shifted right and down by half its own size, so large parts move further than small ones. Mesh images are placed correctly.
Expected: KTX2 images are positioned the same as the PNG images they replace.
Cause
DeferredFactory::decodeImage (renderer/include/rive/renderer/cmd/deferred_render_factory.hpp) needs the image size at record time. It tries Bitmap::decode, then falls back to sniffImageSize (renderer/src/deferred_cmd.cpp). sniffImageSize knows PNG, GIF, WebP and JPEG headers but not KTX2, so a KTX2 image is recorded as 0×0.
The replay side decodes the same bytes through RenderContext::decodeImage, which does recognise KTX2, so the texture itself is fine. On the record side Image::draw translates by -width * originX, -height * originY using the 0×0 size, so the image is drawn from its origin instead of around it. Meshes do not depend on the image size, which is why they look right.
In a release build nothing is logged, because the "image dims unknown at record time" warning is inside #ifndef NDEBUG.
Since Factory.rive.decodeImage and FileAsset.decode reach the same function, I expect KTX2 bytes supplied through an asset loader to behave the same way. I only tested embedded images.
Reproduction steps
- Take a
.rivwith at least one plain (non-mesh) image node with an origin of 0.5, 0.5. - Replace the embedded PNG bytes with a KTX2 file of the same pixel size, for example one made with KTX-Software from a premultiplied PNG:
ktx create --format ASTC_4x4_SRGB_BLOCK --assign-tf srgb --generate-mipmap in.png out.ktx2 - Load it with
File.decode(bytes, riveFactory: Factory.rive)and show it in aRiveWidgeton an iOS device.
The image appears shifted by half its width and height.
I cannot attach the files I used because the artwork is not mine to share. I can build a small synthetic .riv if that would help.
Suggested fix
Reading the size from the KTX2 header in sniffImageSize fixes it for me. I rebuilt only deferred_cmd.cpp with this change, replaced that object in the prebuilt librive_pls_renderer.a for iOS, and the same files then render in the right place.
--- a/renderer/src/deferred_cmd.cpp
+++ b/renderer/src/deferred_cmd.cpp
@@ -24,6 +24,21 @@
h = static_cast<int>(be32(20));
return true;
}
+ // KTX2: 12-byte identifier, then vkFormat, typeSize, pixelWidth and
+ // pixelHeight as little-endian u32 at 12/16/20/24.
+ if (n >= 28 && d[0] == 0xAB && d[1] == 'K' && d[2] == 'T' && d[3] == 'X' &&
+ d[4] == ' ' && d[5] == '2' && d[6] == '0' && d[7] == 0xBB)
+ {
+ auto le32 = [&](size_t i) {
+ return static_cast<uint32_t>(d[i]) |
+ (static_cast<uint32_t>(d[i + 1]) << 8) |
+ (static_cast<uint32_t>(d[i + 2]) << 16) |
+ (static_cast<uint32_t>(d[i + 3]) << 24);
+ };
+ w = static_cast<int>(le32(20));
+ h = static_cast<int>(le32(24));
+ return w > 0 && h > 0;
+ }
// GIF: "GIF87a"/"GIF89a", then width/height little-endian u16 at 6/8.
if (n >= 10 && d[0] == 'G' && d[1] == 'I' && d[2] == 'F')
{Rive Flutter package version
rive 0.15.0-dev.4 with rive_native 0.2.0-dev.4
Flutter version
Flutter 3.47.8 (stable)
Device
iPhone 13 Pro, iOS 27.2.1, Xcode 27. Not tested on Android.
Activity
xcc3641 commentedon Nov 26, 2026
In case it helps anyone else before a fix ships, this is how we applied the change on iOS without rebuilding all of
rive_native. Only one object file differs from the published prebuilt libraries.Copy the
rive_nativepackage out of the Pub cache and point the app at the copy, so the shared cache stays untouched:Keep
ios/rive_marker_ios_setup_completein the copy, otherwise the pod script downloads the prebuilt libraries again and overwrites the change.Apply the diff above to
runtime/renderer/src/deferred_cmd.cpp.Generate the iOS build files. In the copy:
The rename is what
dart run rive_native:setup --builddoes before it callsbuild.sh. We did not need the build to finish, only the makefiles undernative/out/release/ios/universal/.Compile just the one file. Print its command and run it:
cd native/out/release/ios/universal make -n -f rive_pls_renderer.make obj/default/rive_pls_renderer/deferred_cmd.o verbose=1We ran that command with
-flto=fulland-fembed-bitcoderemoved, because the objects in the publishedlibrive_pls_renderer.aare plain Mach-O rather than bitcode.Replace the object in the prebuilt library:
With that, the same KTX2 files render in the right place on an iPhone 13 Pro.
Two things got in the way of a full source build on Xcode 27, unrelated to this issue but worth knowing:
xcodebuild -downloadComponent MetalToolchain). The shaders are not needed for this one object, so we stubbed themetalandmetallibtools instead of installing it."The selected platform is no longer supported by libc++"because the build targets iOS 13 with-Werror. We added-Wno-errorfor the single file.alois-rive commentedon Nov 26, 2026
Thanks a lot for the report, @xcc3641, and for the detailed investigation and suggested patch. It pointed us straight at the cause.
You were right: KTX2 images were recorded as 0×0 because the image-size sniffing didn't recognise the KTX2 header, so
Image::drawskipped the origin offset. We've fixed it along the lines you suggested, with a few extra checks on the header, and added tests. The fix should ship in an upcoming release soon. We'll update this issue when it's out.