Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion desktop/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use rand::Rng;
use rfd::AsyncFileDialog;
use std::fs;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Receiver, Sender, SyncSender};
use std::thread;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -44,6 +46,7 @@ pub(crate) struct App {
persistent_data: PersistentData,
cli: Cli,
startup_time: Option<Instant>,
exiting: Arc<AtomicBool>,
exit_reason: ExitReason,
}

Expand All @@ -67,14 +70,20 @@ impl App {
})
.expect("Error setting Ctrl-C handler");

let exiting = Arc::new(AtomicBool::new(false));

let rendering_app_event_scheduler = app_event_scheduler.clone();
let (start_render_sender, start_render_receiver) = std::sync::mpsc::sync_channel(1);
let exiting_clone = exiting.clone();
std::thread::spawn(move || {
let runtime = tokio::runtime::Runtime::new().unwrap();
loop {
let result = runtime.block_on(DesktopWrapper::execute_node_graph());
rendering_app_event_scheduler.schedule(AppEvent::NodeGraphExecutionResult(result));
let _ = start_render_receiver.recv_timeout(Duration::from_millis(10));
if exiting_clone.load(Ordering::Relaxed) {
break;
}
}
});

Expand Down Expand Up @@ -106,8 +115,9 @@ impl App {
web_communication_startup_buffer: Vec::new(),
persistent_data,
cli,
exit_reason: ExitReason::Shutdown,
startup_time: None,
exiting,
exit_reason: ExitReason::Shutdown,
}
}

Expand All @@ -117,6 +127,10 @@ impl App {
}

fn exit(&mut self, reason: Option<ExitReason>) {
if self.exiting.swap(true, Ordering::Relaxed) {
return;
}
let _ = self.start_render_sender.send(());
if let Some(reason) = reason {
self.exit_reason = reason;
}
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/cef/context/multithreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ impl CefContext for MultiThreadedCefContextProxy {

impl Drop for MultiThreadedCefContextProxy {
fn drop(&mut self) {
cef::shutdown();
// Force dropping underlying context on the UI thread
run_on_ui_thread(move || drop(CONTEXT.take()));
}
}

Expand Down
4 changes: 4 additions & 0 deletions desktop/src/cef/context/singlethreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl CefContext for SingleThreadedCefContext {

impl Drop for SingleThreadedCefContext {
fn drop(&mut self) {
tracing::debug!("Shutting down CEF");

// CEF wants us to close the browser before shutting down, otherwise it may run longer that necessary.
self.browser.host().unwrap().close_browser(1);
cef::shutdown();

// Sometimes some CEF processes still linger at this point and hold file handles to the cache directory.
Expand Down
2 changes: 1 addition & 1 deletion editor/src/messages/viewport/viewport_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl MessageHandler<ViewportMessage, ()> for ViewportMessageHandler {
fn process_message(&mut self, message: ViewportMessage, responses: &mut VecDeque<Message>, _: ()) {
match message {
ViewportMessage::Update { x, y, width, height, scale } => {
assert_ne!(scale, 0., "Viewport scale cannot be zero");
assert!(scale > 0., "Viewport scale must be greater than zero");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly prevents NaN scale values which caused the original panic, it still allows Infinity. An infinite scale could be passed from the frontend and lead to other calculations resulting in Infinity or NaN, potentially causing other issues. Using is_finite() would make this assertion more robust.

Suggested change
assert!(scale > 0., "Viewport scale must be greater than zero");
assert!(scale.is_finite() && scale > 0., "Viewport scale must be finite and greater than zero");

self.scale = scale;

self.bounds = Bounds {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/utility-functions/viewports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export function setupViewportResizeObserver(editor: Editor) {
// TODO: Consider passing physical sizes as well to eliminate pixel inaccuracies since width and height could be rounded differently
const scale = physicalWidth / logicalWidth;

if (!scale || scale <= 0) {
continue;
}
Comment on lines +45 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check !scale works for NaN and 0, but using Number.isFinite() is more explicit and robust. It will correctly handle Infinity, -Infinity, and NaN, which can occur if logicalWidth is zero. This ensures that only valid, finite, positive scale values are sent to the backend.

Suggested change
if (!scale || scale <= 0) {
continue;
}
if (!Number.isFinite(scale) || scale <= 0) {
continue;
}


editor.handle.updateViewport(bounds.x, bounds.y, logicalWidth, logicalHeight, scale);
}
});
Expand Down