Fix the Imaginate node from crashing (#1512)

* Allow generic node input for type inference

* Make imaginate resolution picking depend on the image resolution instead of the transform

* Remove dead code

* Fix console spam after crash

* Fix crash when disconnecting Imaginate node input

* Update Imaginate tool tooltip

---------

Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
Keavon Chambers
2023-12-12 22:39:33 -08:00
committed by GitHub
parent f58aa73edc
commit 83af879a7c
15 changed files with 98 additions and 133 deletions

View File

@@ -96,12 +96,8 @@ r#"
responses.push(res);
}
let responses = responses.pop().unwrap();
let trigger_message = responses[responses.len() - 2].clone();
if let FrontendMessage::TriggerRasterizeRegionBelowLayer { size, .. } = trigger_message {
assert!(size.x > 0. && size.y > 0.);
} else {
panic!();
}
// let trigger_message = responses[responses.len() - 2].clone();
println!("responses: {responses:#?}");
}
}

View File

@@ -5,7 +5,6 @@ use crate::messages::portfolio::document::utility_types::layer_panel::{JsRawBuff
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::HintData;
use document_legacy::LayerId;
use graph_craft::document::NodeId;
use graphene_core::raster::color::Color;
use graphene_core::text::Font;
@@ -92,14 +91,6 @@ pub enum FrontendMessage {
TriggerLoadPreferences,
TriggerOpenDocument,
TriggerPaste,
TriggerRasterizeRegionBelowLayer {
#[serde(rename = "documentId")]
document_id: u64,
#[serde(rename = "layerPath")]
layer_path: Vec<LayerId>,
svg: String,
size: glam::DVec2,
},
TriggerRefreshBoundsOfViewports,
TriggerRevokeBlobUrl {
url: String,

View File

@@ -130,7 +130,7 @@ fn monitor_node() -> DocumentNode {
name: "Monitor".to_string(),
inputs: Vec::new(),
implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_, _, _>"),
manual_composition: Some(concrete!(Footprint)),
manual_composition: Some(generic!(T)),
skip_deduplication: true,
..Default::default()
}

View File

@@ -10,6 +10,7 @@ use graph_craft::concrete;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{DocumentNode, NodeId, NodeInput};
use graph_craft::imaginate_input::{ImaginateMaskStartingFill, ImaginateSamplingMethod, ImaginateServerStatus, ImaginateStatus};
use graphene_core::memo::IORecord;
use graphene_core::raster::{BlendMode, Color, ImageFrame, LuminanceCalculation, NoiseType, RedGreenBlue, RelativeAbsolute, SelectiveColorChoice};
use graphene_core::text::Font;
use graphene_core::vector::style::{FillType, GradientType, LineCap, LineJoin};
@@ -1476,6 +1477,15 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
.executor
.introspect_node_in_network(context.network, &imaginate_node, |network| network.inputs.first().copied(), |frame: &ImageFrame<Color>| frame.transform)
.unwrap_or_default();
let image_size = context
.executor
.introspect_node_in_network(
context.network,
&imaginate_node,
|network| network.inputs.first().copied(),
|frame: &IORecord<(), ImageFrame<Color>>| (frame.output.image.width, frame.output.image.height),
)
.unwrap_or_default();
let resolution = {
use graphene_std::imaginate::pick_safe_imaginate_resolution;
@@ -1493,7 +1503,7 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
} = &document_node.inputs[resolution_index]
{
let dimensions_is_auto = vec2.is_none();
let vec2 = vec2.unwrap_or_else(|| round([transform.matrix2.x_axis, transform.matrix2.y_axis].map(DVec2::length).into()));
let vec2 = vec2.unwrap_or_else(|| round((image_size.0 as f64, image_size.1 as f64).into()));
let layer_path = context.layer_path.to_vec();
widgets.extend_from_slice(&[

View File

@@ -397,7 +397,9 @@ fn list_tools_in_groups() -> Vec<Vec<ToolAvailability>> {
vec![
// Raster tool group
// ToolAvailability::Available(Box::<imaginate_tool::ImaginateTool>::default()), // TODO: Fix and reenable ASAP
ToolAvailability::ComingSoon(ToolEntry::new(ToolType::Heal, "RasterImaginateTool").tooltip("Coming Soon: Imaginate Tool - Temporarily Disabled Until Fixed (Early December 2023)")),
ToolAvailability::ComingSoon(
ToolEntry::new(ToolType::Heal, "RasterImaginateTool").tooltip("Coming Soon: Imaginate Tool - Temporarily disabled, please use Imaginate node directly from graph"),
),
ToolAvailability::Available(Box::<brush_tool::BrushTool>::default()),
ToolAvailability::ComingSoon(ToolEntry::new(ToolType::Heal, "RasterHealTool").tooltip("Coming Soon: Heal Tool (J)")),
ToolAvailability::ComingSoon(ToolEntry::new(ToolType::Clone, "RasterCloneTool").tooltip("Coming Soon: Clone Tool (C)")),

View File

@@ -447,7 +447,10 @@ impl NodeGraphExecutor {
};
let introspection_node = find_node(wrapped_network)?;
let introspection = self.introspect_node(&[node_path, &[introspection_node]].concat())?;
let downcasted: &T = <dyn std::any::Any>::downcast_ref(introspection.as_ref())?;
let Some(downcasted): Option<&T> = <dyn std::any::Any>::downcast_ref(introspection.as_ref()) else {
log::warn!("Failed to downcast type for introspection");
return None;
};
Some(extract_data(downcasted))
}