fix: updateImage and draw should not throw#482
Merged
swederik merged 2 commits intocornerstonejs:masterfrom Sep 13, 2021
Merged
fix: updateImage and draw should not throw#482swederik merged 2 commits intocornerstonejs:masterfrom
swederik merged 2 commits intocornerstonejs:masterfrom
Conversation
fbd7c1b to
c8cbd26
Compare
mikehazell
commented
Sep 9, 2020
c8cbd26 to
9472274
Compare
Contributor
Author
|
NOTE: I've removed |
Contributor
Author
|
Hey @dannyrb, any thoughts on this? |
zakjholt
approved these changes
Nov 10, 2020
zakjholt
left a comment
There was a problem hiding this comment.
This seems like it'll solve an issue I'm currently running into with the layers api
Member
|
Thanks! |
Member
|
🎉 This PR is included in version 2.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow calling
updateImageordrawwhether an image has been loaded or notChanges
This PR:
updateImageanddrawmethods.drawImageSyncis correctly verifying an elements state.drawImageSyncbecause of an edge case condition where the element has a layer added without an image.Some context
I'm not sure if this was the original intention of
updateImagebut it is often used to tell cornerstone that the canvas state is invalid and needs to be re-rendered.There are several similar methods
drawImage,draw,invalidate,invalidateImageIdanddrawInvalidated.needsRedrawandinvalidon one or moreenabledElement's.drawandupdateImagecurrently have a check to see if the element has an image loaded.This check is not needed
drawImageSyncis the method which actually causes something to be rendered to the canvas and is therefore the method which would encounter an error if some required state were missing. The implementation of this method already contains checks to ensure theenabledElementhas all the state required to render and will quietly return early if it does not.So if these checks are working correctly, there is no need for
draworupdateImageto also check this state.Why is it worth changing this
The most obvious example of
updateImagethrowing causing pain is when a cornerstone tool is changing mode.The tool may need to tell cornerstone that the state of the canvas needs to be updated. For example to stop showing a cursor, or to redraw without an annotation.
We can see a case of this causing a crashing bug here:
cornerstonejs/cornerstoneTools#1303
This has also been an issue with the BrushTool.