Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BaseBrushTool.js): prevents a crash in passiveCallback #925

Merged
Merged
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
8 changes: 7 additions & 1 deletion src/tools/base/BaseBrushTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ class BaseBrushTool extends BaseTool {
*/
// eslint-disable-next-line no-unused-vars
passiveCallback(evt) {
external.cornerstone.updateImage(this.element);
try {
external.cornerstone.updateImage(this.element);
Copy link
Member

Choose a reason for hiding this comment

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

I really wish updateImage and similar methods were safe to call with elements that don't have a loaded image or are not called with an enabled element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree.

Particularly updateImage. It doesn't access the image itself, it just calls drawImage which also doesn't touch the image but sets enabledElement.needsRedraw.

needsRedraw is then checked in the run-loop which also checks to make sure the image is loaded.

https://github.com/cornerstonejs/cornerstone/blob/f3b4accef3a700b0719e8373c08c414a1448b563/src/enable.js#L97-L99

There's nothing here that would break if updateImage was called when no image is loaded.

} catch (error) {
// It is possible that the image has not been loaded
// when this is called.
return;
}
}

/**
Expand Down