-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: Extract functions no longer throw an error if the frame is empty #9363
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 5691829:
|
@@ -234,8 +234,8 @@ export class CanvasExtract implements ISystem, IExtract | |||
|
|||
const x = Math.round(frame.x * resolution); | |||
const y = Math.round(frame.y * resolution); | |||
const width = Math.round(frame.width * resolution); | |||
const height = Math.round(frame.height * resolution); | |||
const width = Math.max(Math.round(frame.width * resolution), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like this! perhaps we set to 1, but also log a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. If the render target resolution is low enough, something like extract.pixels(rt, new Rectangle(x, y, 1, 1))
to pick the the color of the pixel at (x, y) might spam an warning unnecessarily. At resolution above 1 if might return more than the 1 pixel we need. I was thinking maybe extract.pixels(rt, new Rectangle(x, y, 0, 0))
could be useful to just extract the one pixel at that point, but the rounding behavior doesn't work for that. Maybe we should use frame.ceil()
.
What would be better is if we can assert the input before doing anything and throw a specific user-friendly error instead of defaulting to 1x1. |
Should we switch to |
I think ceil would make sense, yes. |
Maybe defaulting to 1x1 and no error is better after all considering |
Reverted the throwing of an error: If Reverted the |
This has deviated a little from the original title of the PR. How would you rename this now? |
Technically one of the others PR merged before this one already prevented the errors, but didn't mention it. Not sure how to describe the change in a single sentence:
|
@dev7355608 could you resolve conflicts so I could merge this? |
The alternative is that we don't allow empty frames and throw an error ourselves if
frame
is empty that is perhaps more more helpful can the error messages generated bygetImageData
etc.Pre-Merge Checklist
npm run lint
)npm run test
)