Skip to content

Conversation

@Ayush2k02
Copy link

@Ayush2k02 Ayush2k02 commented Dec 28, 2025

Simple enough fix which skips the flawed deduplication check and generates a different id ( UUID ) for each new image

Screen.Recording.2025-12-28.at.7.46.56.PM.mov

Closes #3533

@Ayush2k02 Ayush2k02 changed the title Fix/rasterize node document leakage fix: rasterize node document leakage Dec 28, 2025
@Ayush2k02 Ayush2k02 force-pushed the fix/rasterize-node-document-leakage branch 2 times, most recently from 551fbb5 to 3ba2ad3 Compare December 29, 2025 05:57
@Ayush2k02 Ayush2k02 marked this pull request as draft December 29, 2025 05:59
@Ayush2k02 Ayush2k02 force-pushed the fix/rasterize-node-document-leakage branch from 3ba2ad3 to 85c0f16 Compare December 29, 2025 06:12
}

if render_params.to_canvas() {
let id = row.source_node_id.map(|x| x.0).unwrap_or_else(|| {
Copy link
Author

Choose a reason for hiding this comment

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

Don't fully understand this syntax but from what I can see this generates an ID for an image and was used in deduplication for similar images . Since we are no more deduplicating similar images and each new image is getting its own ID , figured it would be best to use a simple generate_uuid instead

Copy link
Author

Choose a reason for hiding this comment

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

Without doing so , its still causing the same image leakage for me

@Ayush2k02 Ayush2k02 marked this pull request as ready for review December 29, 2025 06:47
@Ayush2k02 Ayush2k02 requested a review from 0HyperCube December 29, 2025 06:49
@Ayush2k02
Copy link
Author

Ayush2k02 commented Dec 29, 2025

This ones ready to be reviewed from my side

@TrueDoctor
Copy link
Member

I need a bit more time to look at this, the workaround implemented here does not feel quite right, I'm also wondering if this will effect the performane as it is currently implemented

@0HyperCube
Copy link
Contributor

0HyperCube commented Dec 29, 2025

@TrueDoctor yes it will be bad for performance.

The hashing code for images is included below:

// TODO: Evaluate if this will be a problem for our use case.
/// Warning: This is an approximation of a hash, and is not guaranteed to not collide.
impl<P: Hash + Pixel> Hash for Image<P> {
fn hash<H: Hasher>(&self, state: &mut H) {
const HASH_SAMPLES: u64 = 1000;
let data_length = self.data.len() as u64;
self.width.hash(state);
self.height.hash(state);
for i in 0..HASH_SAMPLES.min(data_length) {
self.data[(i * data_length / HASH_SAMPLES) as usize].hash(state);
}
}
}

However this will lead to very many conflicts when you have images such as the cases below:
ellipse_thin_stroke
rectangle_thin_stroke

Since there are 1000x1000 pixels and the vast majority are white, these two both hash to the same thing.

It is necessary for correctness that these two different images aren't treated as the same thing by the SVG rendering code. Otherwise it looks like the rasterize node is broken. Actually the rasterization works fine.

An example graphite file where this collision occurs is include below:
rasterize_node_conflicts.graphite

@TrueDoctor
Copy link
Member

Yeah the hash is broken, I guess we could do an eq check after the hash calculation, that should hopefully be fast enough. But I guess we would need to benchmark if disabling the deduplication alltogether would be faster

@Ayush2k02
Copy link
Author

Ayush2k02 commented Dec 29, 2025

An example graphite file where this collision occurs is include below:
rasterize_node_conflicts.graphite , like do we import this JSON somewhere to load this ourselves ?

What is this ?? and how is this used ?

@0HyperCube
Copy link
Contributor

@Ayush2k02 Yes, you can import this graphite file into the Graphite editor. file -> open and select the file.

Note that the extension is .graphite.json since GitHub doesn't directly support uploading files using .graphite extension. You can either change the extension after you download the file or just directly select file (you might have to alter the filter in your file picker).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rasterize node: the rasterized image is leaking from one document to another

3 participants