-
Notifications
You must be signed in to change notification settings - Fork 222
Description
Hi Rive team 👋
I've encountered a crash when using rive_native on iOS in combination with plugins like workmanager or home_widget. These plugins typically use setPluginRegistrantCallback to support multiple FlutterEngine instances (e.g. for background tasks).
This leads to multiple calls to registerWithRegistrar in rive_native_plugin.mm, and ultimately causes a crash:
std::unique_lock<std::mutex> lock(rt->_mutex); // <- EXC_BAD_ACCESS
Each new call to registerWithRegistrar method replaces the existing instance which I guess leads to that issue.
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar
{
FlutterMethodChannel* channel =
[FlutterMethodChannel methodChannelWithName:@"rive_native"
binaryMessenger:[registrar messenger]];
riveNativePluginInstance =
[[RiveNativePlugin alloc] initWithTextures:[registrar textures]];
[registrar addMethodCallDelegate:riveNativePluginInstance channel:channel];
}✅ Possible solution
Adding a guard to prevent reinitialization of the global riveNativePluginInstance solves the crash. However, I haven’t verified if this introduces any side effects in more complex setups. I just wanted to share my findings in case it's helpful or something you’d want to address in the plugin directly.
