GraphiteEditor / Graphite

2D vector & raster editor that melds traditional layers & tools with a modern node-based, non-destructive, procedural workflow.
https://graphite.rs
Apache License 2.0
9.07k stars 437 forks source link

[Crash Report] Brush tool on top of shapes crashes #2057

Open DaraghD opened 5 days ago

DaraghD commented 5 days ago

Describe the Crash Using brush tool ontop of stuff

Steps To Reproduce Describe precisely how the crash occurred, step by step, starting with a new editor window.

  1. Open a local build of graphite with debug assertions enabled.
  2. Delete the artboards (or create an infinite document).
  3. Draw a with the brush tool.
  4. Crash

Additional Details Provide any further information or context that you think would be helpful in fixing the issue. Screenshots or video can be linked or attached to this issue. Screencast_20241019_214255.webm Browser and OS Firefox 130, Arch Linux

Stack Trace Copied from the crash dialog in the Graphite editor:

panicked at editor/src/messages/portfolio/document/utility_types/document_metadata.rs:207:9:
LayerNodeIdentifier::ROOT_PARENT cannot be converted to NodeId

createPanicManager/<@http://localhost:8080/src/io-managers/panic.ts:9:24
callCallback@http://localhost:8080/src/wasm-communication/subscription-router.ts:25:17
handleJsMessage@http://localhost:8080/src/wasm-communication/subscription-router.ts:33:5
createEditor/handle<@http://localhost:8080/src/wasm-communication/editor.ts:21:19
__wbg_get_imports/imports.wbg.__wbg_call_5fb7c8066a4a4825/<@http://localhost:8080/wasm/pkg/graphite_wasm.js:2302:26
handleError@http://localhost:8080/wasm/pkg/graphite_wasm.js:334:18
__wbg_get_imports/imports.wbg.__wbg_call_5fb7c8066a4a4825@http://localhost:8080/wasm/pkg/graphite_wasm.js:2301:67
graphite_wasm.wasm.__wbg_call_5fb7c8066a4a4825 externref shim@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[25341]:0xf2de18
graphite_wasm.wasm.js_sys::Function::call2::h2987cf074cae0c1c@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[20861]:0xee8259
graphite_wasm.wasm.graphite_wasm::editor_api::EditorHandle::send_frontend_message_to_js::ha4d06d6e54353418@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[2547]:0x828688
graphite_wasm.wasm.std::thread::local::LocalKey<T>::with::hd61b91dd691f48fa@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[14604]:0xdefa3f
graphite_wasm.wasm.graphite_wasm::panic_hook::h030f010a04469e60@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[1485]:0x69d2a0
graphite_wasm.wasm.core::ops::function::Fn::call::h326de5e8a792cab9@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[31492]:0xf51280
graphite_wasm.wasm.std::panicking::rust_panic_with_hook::h2adea73e77f917f4@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[14510]:0xdeadf2
graphite_wasm.wasm.std::panicking::begin_panic_handler::{{closure}}::hdbd2e392ad02e052@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[16650]:0xe4fc5b
graphite_wasm.wasm.std::sys::backtrace::__rust_end_short_backtrace::h7d3184d23478fc66@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[31379]:0xf50e45
graphite_wasm.wasm.rust_begin_unwind@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[24150]:0xf21538
graphite_wasm.wasm.core::panicking::panic_fmt::h1bc190b9665013d3@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[24151]:0xf21565
graphite_wasm.wasm.graphite_editor::messages::portfolio::document::utility_types::document_metadata::DocumentMetadata::transform_to_viewport::he49d91589ade3208@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[7890]:0xbdc3a2
graphite_wasm.wasm.<graphite_editor::messages::tool::tool_messages::brush_tool::BrushToolFsmState as graphite_editor::messages::tool::utility_types::Fsm>::transition::h0ef21faf21cb9338@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[455]:0x33d132
graphite_wasm.wasm.graphite_editor::messages::tool::utility_types::Fsm::process_event::hb62f32080768d26d@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[4418]:0x9e43e6
graphite_wasm.wasm.<graphite_editor::messages::tool::tool_messages::brush_tool::BrushTool as graphite_editor::utility_traits::MessageHandler<graphite_editor::messages::tool::tool_message::ToolMessage,&mut graphite_editor::messages::tool::utility_types::ToolActionHandlerData>>::process_message::h1e106856f8443c03@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[3523]:0x92ccd9
graphite_wasm.wasm.<graphite_editor::messages::tool::tool_message_handler::ToolMessageHandler as graphite_editor::utility_traits::MessageHandler<graphite_editor::messages::tool::tool_message::ToolMessage,graphite_editor::messages::tool::tool_messa

ge_handler::ToolMessageData>>::process_message::h5a01f2f51f67f0b3@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[626]:0x4413a4
graphite_wasm.wasm.graphite_editor::dispatcher::Dispatcher::handle_message::h4472643b48920805@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[543]:0x3d01ac
graphite_wasm.wasm.graphite_editor::application::Editor::handle_message::h82d0aeb69e52fc8b@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[23515]:0xf190d5
graphite_wasm.wasm.std::thread::local::LocalKey<T>::with::h0b821da661c2c76f@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[5296]:0xa81e44
graphite_wasm.wasm.graphite_wasm::editor_api::EditorHandle::dispatch::h32227cb36385de82@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[8375]:0xc0ff4f
graphite_wasm.wasm.editorhandle_onMouseDown@http://localhost:8080/wasm/pkg/graphite_wasm_bg.wasm:wasm-function[8796]:0xc3b60d
onMouseDown@http://localhost:8080/wasm/pkg/graphite_wasm.js:725:14
onPointerDown@http://localhost:8080/src/io-managers/input.ts:116:21
action@http://localhost:8080/src/io-managers/input.ts:25:77
0HyperCube commented 5 days ago

Thanks for the bug report @DaraghD.

I have amended your issue since you are running into a debug assert (so clearly you wasn't using editor.graphite.rs).

The issue occurs because the brush tool tries to find the transform of the parent layer. However if the parent layer is the root layer, a crash occurs since we apparently are forbidden from finding the transform of the root layer. In release mode, we correctly use the document_to_viewport transform.

adamgerhant commented 4 days ago

I think this is because I forgot to migrate the brush tool to using the message buffering and using the transform of its own layer, as returned from the render output.