Fix layer deletion bugs when tools are in use (#684)

* Added test case of layer delete bug

* Fixed crash in `PenTool`

Updated the document `MessageHandler` to cancel all active tools if the
layer is deleted.  This prevents the tools from crashing due to the
layer being pulled from under them.

* Moved Abort into pre-graphene DeleteLayer message

* Renamed test case for clarity

* Moved tool crash tests to the `tools` module

* Added `test-case` to the dev dependencies

* Added crash test case for all tools

* Ran cargo fmt

Co-authored-by: otdavies <oliver@psyfer.io>
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Alexi
2022-06-24 09:35:07 -05:00
committed by Keavon Chambers
co-authored by otdavies Keavon Chambers
parent 5016abd971
commit 91219cbe64
5 changed files with 89 additions and 1 deletions
+29
View File
@@ -4,3 +4,32 @@ pub mod tool_message;
pub mod tool_message_handler;
pub mod tools;
pub mod vector_editor;
#[cfg(test)]
mod tool_crash_on_layer_delete_tests {
use crate::communication::set_uuid_seed;
use crate::misc::test_utils::EditorTestUtils;
use crate::viewport_tools::tool::ToolType;
use crate::{DocumentMessage, Editor};
use test_case::test_case;
#[test_case(ToolType::Pen ; "while using pen tool")]
#[test_case(ToolType::Freehand ; "while using freehand tool")]
#[test_case(ToolType::Spline ; "while using spline tool")]
#[test_case(ToolType::Line ; "while using line tool")]
#[test_case(ToolType::Rectangle ; "while using rectangle tool")]
#[test_case(ToolType::Ellipse ; "while using ellipse tool")]
#[test_case(ToolType::Shape ; "while using shape tool")]
#[test_case(ToolType::Path ; "while using path tool")]
fn should_not_crash_when_layer_is_deleted(tool: ToolType) {
set_uuid_seed(0);
let mut test_editor = Editor::new();
test_editor.select_tool(tool);
test_editor.lmb_mousedown(0.0, 0.0);
test_editor.move_mouse(100.0, 100.0);
test_editor.handle_message(DocumentMessage::DeleteSelectedLayers);
}
}