From 74a9ccfaad1a09696fc4a595533de16b61329698 Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 20 Jan 2023 11:22:56 -0500 Subject: [PATCH] hot reload fix --- veilid-core/proto/veilid.capnp | 11 +++-------- veilid-flutter/rust/src/dart_ffi.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/veilid-core/proto/veilid.capnp b/veilid-core/proto/veilid.capnp index 55c40b2b..f38acab9 100644 --- a/veilid-core/proto/veilid.capnp +++ b/veilid-core/proto/veilid.capnp @@ -156,17 +156,12 @@ using ValueSeqNum = UInt32; # sequence numbers for v struct ValueKey @0xe64b0992c21a0736 { publicKey @0 :ValueID; # the location of the value - subkey @1 :Text; # the name of the subkey (or empty if the whole key) + subkey @1 :Text; # the name of the subkey (or empty for the default subkey) } -# struct ValueKeySeq { -# key @0 :ValueKey; # the location of the value -# seq @1 :ValueSeqNum; # the sequence number of the value subkey -# } - struct ValueData @0xb4b7416f169f2a3d { - data @0 :Data; # value or subvalue contents - seq @1 :ValueSeqNum; # sequence number of value + seq @0 :ValueSeqNum; # sequence number of value + data @1 :Data; # value or subvalue contents } # Operations diff --git a/veilid-flutter/rust/src/dart_ffi.rs b/veilid-flutter/rust/src/dart_ffi.rs index 182824a2..3956f11b 100644 --- a/veilid-flutter/rust/src/dart_ffi.rs +++ b/veilid-flutter/rust/src/dart_ffi.rs @@ -19,6 +19,7 @@ use tracing_subscriber::*; // Globals lazy_static! { + static ref CORE_INITIALIZED: Mutex = Mutex::new(false); static ref VEILID_API: AsyncMutex> = AsyncMutex::new(None); static ref FILTERS: Mutex> = Mutex::new(BTreeMap::new()); @@ -144,6 +145,17 @@ pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPos #[no_mangle] #[instrument] pub extern "C" fn initialize_veilid_core(platform_config: FfiStr) { + + // Only do this once, ever + // Until we have Dart native finalizers running on hot-restart, this will cause a crash if run more than once + { + let mut core_init = CORE_INITIALIZED.lock(); + if *core_init { + return; + } + *core_init = true; + } + let platform_config = platform_config.into_opt_string(); let platform_config: VeilidFFIConfig = veilid_core::deserialize_opt_json(platform_config) .expect("failed to deserialize plaform config json");