Skip to content

Commit f426085

Browse files
catching more search region to screen size mismatches
1 parent 5ae993a commit f426085

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/screen.class.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,17 @@ export class Screen {
101101

102102
return new Promise<Region>(async (resolve, reject) => {
103103
try {
104-
if ( searchRegion.left > await screenSize.width || searchRegion.top > screenSize.height ) {
105-
throw new Error(`Requested search region (${searchRegion.left}, ${searchRegion.top}, ${searchRegion.width}, ${searchRegion.height}) lies beyond screen boundaries (${screenSize.width}, ${screenSize.height})`);
104+
if ( region.left < 0 || region.top < 0 || region.width < 0 || region.height < 0 ) {
105+
throw new Error(`Negative values in search region ${region}`)
106+
}
107+
if ( isNaN(region.left) || isNaN(region.top) || isNaN(region.width) || isNaN(region.height) ) {
108+
throw new Error(`NaN values in search region ${region}`)
109+
}
110+
if ( region.width < 2 || region.height < 2 ) {
111+
throw new Error(`Search region ${region} is not large enough. Must be at least two pixels in both width and height.`)
112+
}
113+
if ( region.left + region.width > screenSize.width || region.top + region.height > screenSize.height ) {
114+
throw new Error(`Search region ${region} extends beyond screen boundaries (${screenSize.width}x${screenSize.height})`)
106115
}
107116
const matchResult = await this.vision.findOnScreenRegion(matchRequest);
108117
if (matchResult.confidence >= minMatch) {

0 commit comments

Comments
 (0)