From 901505e8be5ecef1e4dcd5812cefa897639c0d5c Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:49:11 +0800 Subject: [PATCH] fix: macos, load multi dylib instances (#8731) Multiple dylib instances will cause some global instances to be invalid. eg. lazy_static objects in rust side, will be created more than once. Signed-off-by: fufesou --- flutter/lib/models/native_model.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/flutter/lib/models/native_model.dart b/flutter/lib/models/native_model.dart index 0b70e30c8..b99cf2e7f 100644 --- a/flutter/lib/models/native_model.dart +++ b/flutter/lib/models/native_model.dart @@ -117,9 +117,13 @@ class PlatformFFI { ? DynamicLibrary.open('librustdesk.so') : isWindows ? DynamicLibrary.open('librustdesk.dll') - : isMacOS - ? DynamicLibrary.open("liblibrustdesk.dylib") - : DynamicLibrary.process(); + : + // Use executable itself as the dynamic library for MacOS. + // Multiple dylib instances will cause some global instances to be invalid. + // eg. `lazy_static` objects in rust side, will be created more than once, which is not expected. + // + // isMacOS? DynamicLibrary.open("liblibrustdesk.dylib") : + DynamicLibrary.process(); debugPrint('initializing FFI $_appType'); try { _session_get_rgba = dylib.lookupFunction("session_get_rgba");