Sandbox node graph execution on native targets and attempt recovery from panics on Wasm (#1846)

* Test out wasm unwinding

* Implement panic catching for native targets

* Hack in support for recovering panics in wasm

* Keep debug info in release builds

* Check for DynAnyNode in Backtrace because that can't be inlined as well

* Improve error dialog

* Use a mutex for storing the frontend state instead of a RefCell

* Code review

* Update crash text

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2024-07-29 01:46:44 +02:00
committed by GitHub
parent 06177597ae
commit 5b1d3a0ae4
8 changed files with 110 additions and 46 deletions

View File

@@ -4,7 +4,6 @@ use crate::messages::portfolio::document::node_graph::document_node_types::wrap_
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::prelude::*;
use futures::lock::Mutex;
use graph_craft::concrete;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{generate_uuid, DocumentNodeImplementation, NodeId, NodeNetwork};
@@ -26,6 +25,7 @@ use interpreted_executor::dynamic_executor::{DynamicExecutor, ResolvedDocumentNo
use glam::{DAffine2, DVec2, UVec2};
use once_cell::sync::Lazy;
use spin::Mutex;
use std::sync::mpsc::{Receiver, Sender};
use std::sync::Arc;
@@ -120,7 +120,7 @@ impl NodeGraphUpdateSender for InternalNodeGraphUpdateSender {
}
}
pub(crate) static NODE_RUNTIME: Lazy<Mutex<Option<NodeRuntime>>> = Lazy::new(|| Mutex::new(None));
pub static NODE_RUNTIME: Lazy<Mutex<Option<NodeRuntime>>> = Lazy::new(|| Mutex::new(None));
impl NodeRuntime {
pub fn new(receiver: Receiver<NodeRuntimeMessage>, sender: Sender<NodeGraphUpdate>) -> Self {
@@ -377,7 +377,7 @@ impl NodeRuntime {
}
pub async fn introspect_node(path: &[NodeId]) -> Option<Arc<dyn std::any::Any>> {
let runtime = NODE_RUNTIME.lock().await;
let runtime = NODE_RUNTIME.lock();
if let Some(ref mut runtime) = runtime.as_ref() {
return runtime.executor.introspect(path).flatten();
}
@@ -385,14 +385,14 @@ pub async fn introspect_node(path: &[NodeId]) -> Option<Arc<dyn std::any::Any>>
}
pub async fn run_node_graph() {
let mut runtime = NODE_RUNTIME.lock().await;
let Some(mut runtime) = NODE_RUNTIME.try_lock() else { return };
if let Some(ref mut runtime) = runtime.as_mut() {
runtime.run().await;
}
}
pub async fn replace_node_runtime(runtime: NodeRuntime) -> Option<NodeRuntime> {
let mut node_runtime = NODE_RUNTIME.lock().await;
let mut node_runtime = NODE_RUNTIME.lock();
node_runtime.replace(runtime)
}