Fix window point conversion functions not exposing failure#9269
Conversation
michaelDCurran
left a comment
There was a problem hiding this comment.
In some places you are catching exceptions and logging a debugWarning, but then it seems you're still going on and using the values you could not get. You'd either need to return some kind of safe value from the function or raise the original exception again.
| try: | ||
| right,bottom=windowUtils.physicalToLogicalPoint(self.obj.windowHandle,right,bottom) | ||
| except RuntimeError: | ||
| log.debugWarning("physicalToLogicalPoint failed for bottom right", exc_info=True) |
There was a problem hiding this comment.
Should not this return from the function? if there is a runtimeError, then some of left,,top,right or button are going to not exist or be wrong...
There was a problem hiding this comment.
I'm not sure about this one. Returning from the function results in no text being returned at all. I guess your opinion is that it might be better to return no text at all rather than the wrong text. That makes sense, but then we really need to log something on the error level.
…onversionFunctions
|
@feerrenrut: This pull requests changes the behavior of some winUser and windowUtils helper functions. Therefore looking at this to be merged into 2019.3 might be a good idea, since it introduces backwards incompatible changes (i.e. these functions now raise exceptions where they didn't before). |
|
@michaelDCurran: I'd like to bring this under your attention again, as this introduces backwards incompatible changes for add-ons using these functions. |
|
PR introduces Flake8 errors 😲 See test results for Failed build of commit eb06de5eb2 |
| winUser.RECT(left, top, left + width, top + height), None, | ||
| winUser.RDW_INVALIDATE | winUser.RDW_UPDATENOW) | ||
| # Conversion to client coordinates may fail if the window handle of this object is incorrect. | ||
| # This will most likely be caused by a died window. |
| wcharToInt(next(cpBufIt)), | ||
| wcharToInt(next(cpBufIt)) | ||
| ) | ||
| if right < left: |
There was a problem hiding this comment.
Do you know under what circumstances this becomes reversed? can you put a comment here explaining this at least?
There was a problem hiding this comment.
I'm not 100% sure, but my theory is that this happens in case of left to right languages.
There was a problem hiding this comment.
Thinking more about this, I think it would be better to split this specific fix out into a new pr.
|
this pr has conflicts now. |
|
Fixed now. |
|
hi |
|
Sorry, conflicts again. |
|
Conflict is now fixed. |
|
hi |
|
Moved this to the 2020.1 milestone. Needs a lot of testing. |
|
Note that this pr now causes errors like this: This is no mistake in this pr, rather, it is exactly proving the point that this pr was necessary. Effort should be put into finding out why these errors occur in order to fix them properly. |
|
This pr seems to be causing a few issues namely #10751 and #10704. In addition it makes working with autocomplete in Notepad++ quite inefficient, as more often than not conversion of coordinates fails for autocomplete items resulting in constant error sound while typing. |
|
Yes, I agree this needs a revert in order for it to be fixed. |
Link to issue number:
None
Summary of the issue:
There are 4 functions wrappers related to screen, client, logical and physical coordinate conversions.
These functions take a window handle and a point structure and return 1 on success and 0 on failure. The user32 functions also set the last error when the functions fail. The point in the structure is used to calculate a new point, and on success, the coordinates in the structure are replaced. On failure, the coordinates stay the same.
However, the wrappers of these functions silently return whatever is in the structure, thereby silently ignoring whether the underlying function succeeded or failed.
As far as I've seen, for the user32 functions this is only a problem when giving it a wrong window handle. Converting coordinates falling out of the client area of the window works just fine. However, for physicalToLogicalPoint and logicalToPhysicalPoint, the functions also fail when the given coordinates fall outside the window. While normally, providing the wrong coordinates to these functions should not happen, not being able to see whether the underlying function succeeded or failed is problematic for debugging reasons.
Description of how this pull request fixes the issue:
Testing performed:
This is pretty hard to test. I stumbled upon this bug when testing the highlighter in the vision framework (#9064) as that converts physical to logical rectangle coordinates. It silently seemed to fail the conversion of the top left coordinates where it succeeded in converting the bottom right coordinates, resulting in a malformed rectangle.
Known issues with pull request:
None
Change log entry: