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

Conversation

mikehazell
Copy link
Contributor

prevents a crash when _repeatGlobalToolHistory replays setting tool mode passive for brush tools

fix #924

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix

  • What is the current behavior? (You can also link to an open issue here)

Crashing Bug: using the Brush tool with globalToolSyncEnabled can cause the application to crash when a new element is enabled.

  • _repeatGlobalToolHistory replays all tool changes on a new element before the image is loaded
  • BaseBrushTool calls cornerstone.updateImage in it's passiveCallback
  • cornerstone.updateImage will crash if the image is not loaded
  • What is the new behavior (if this is a feature change)?

Wrapped the call to updateImage in a try ... catch.

This should be seen as a temporary fix. A more permanent fix could be to keep track of the current tool state instead of recording and replaying changes. Alternatively, there appears to be no reason why cornerstone.updateImage need to crash when the image is not loaded so changing this behaviour could be more effective.

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

No

prevents a crash when _repeatGlobalToolHistory replays setting tool mode passive for brush tools

fix cornerstonejs#924
@codecov
Copy link

codecov bot commented May 7, 2019

Codecov Report

Merging #925 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #925      +/-   ##
==========================================
- Coverage   11.73%   11.73%   -0.01%     
==========================================
  Files         218      218              
  Lines        7157     7159       +2     
  Branches     1124     1124              
==========================================
  Hits          840      840              
- Misses       5342     5344       +2     
  Partials      975      975
Impacted Files Coverage Δ
src/tools/base/BaseBrushTool.js 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2969865...8b32801. Read the comment docs.

@@ -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.

@dannyrb
Copy link
Member

dannyrb commented May 7, 2019

LGTM 👍

@dannyrb dannyrb merged commit 8480029 into cornerstonejs:master May 7, 2019
@dannyrb
Copy link
Member

dannyrb commented May 7, 2019

🎉 This PR is included in version 3.7.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

brush tool's passiveCallback throws when changing image if globalToolSyncEnabled is true
2 participants