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

The find method ends abnormally #4

Open
uouuou opened this issue Jan 29, 2024 · 1 comment
Open

The find method ends abnormally #4

uouuou opened this issue Jan 29, 2024 · 1 comment

Comments

@uouuou
Copy link

uouuou commented Jan 29, 2024

bitmap version (or commit ref): v0.10.0-beta3.2

  • Go version:1.20.13

  • Gcc version: gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

  • Operating system and bit: Win11

  • Provide example code:

        package main
        
        import (
            "fmt"
            "github.com/vcaesar/bitmap"
        )
        
        func main() {
            img := bitmap.Open("iDontExist.png") // nil
            x, y := bitmap.Find(img)
            fmt.Println(x, y) // -1 -1
        }
      Exception 0xc0000005 0x0 0xc0005151b6 0x67f792
      PC=0x67f792
      signal arrived during external code execution
      
      runtime.cgocall(0x683860, 0xc0000879c0)
          C:/Users/win/go/go1.20.13/src/runtime/cgocall.go:157 +0x4a fp=0xc000087998 sp=0xc000087960 pc=0x494a6a
      github.com/vcaesar/bitmap._Cfunc_find_bitmap(0x22e7ebc7f80, 0x22e7ebc2990, 0x3c23d70a)
          _cgo_gotypes.go:351 +0x58 fp=0xc0000879c0 sp=0xc000087998 pc=0x64b918
      github.com/vcaesar/bitmap.internalFind.func1(0x781e20?, 0xc0002be000?, 0x3f847ae147ae147b)
          N:/GO/pkg/mod/github.com/vcaesar/[email protected]/bitmap.go:114 +0x8e fp=0xc000087a10 sp=0xc0000879c0 pc=0x64bb6e
      github.com/vcaesar/bitmap.internalFind(0xc000018200?, 0x29?, 0xc000087a70?)
          N:/GO/pkg/mod/github.com/vcaesar/[email protected]/bitmap.go:114 +0x19 fp=0xc000087a38 sp=0xc000087a10 pc=0x64ba99
      github.com/vcaesar/bitmap.Find(0x7f9840?, {0xc000087c28, 0x1, 0x1?})
          N:/GO/pkg/mod/github.com/vcaesar/[email protected]/bitmap.go:143 +0xa5 fp=0xc000087a80 sp=0xc000087a38 pc=0x64bc65
    

Description

This should be some memory out of bounds. I don't have a good solution for this problem. I would like developers to confirm it. Thank you
. Also, this is a problem that only occurs with frequent use.

@uouuou
Copy link
Author

uouuou commented Jan 30, 2024

定位到:
MMRGBHex ncolor = MMRGBHexAtPoint(needle, scan.x, scan.y);
这个位置报错的, Exception 0xc0000005 0x0 0xc0005151b6 0x67f792 PC=0x67f792
通过分析观察应该是因为协程的并发速度比较快导致内存地址发生了变化或者什么其他未知原因
这个问题不知道该怎么解决我已经对

// 检查scan.x和scan.y是否在needle的边界内,如果超出边界,则返回错误
            if (scan.x < 0 || scan.x >= needle->width || scan.y < 0 || scan.y >= needle->height) {
                return 0;
            }
            // 检查offset.x + scan.x和offset.y + scan.y是否在haystack的边界内
            if (offset.x + scan.x < 0 || offset.x + scan.x >= haystack->width || offset.y + scan.y < 0 || offset.y + scan.y >= haystack->height) {
                // 如果超出边界,返回0
                return 0;
            }
            //再次检查needle是否为空,如果为空,则返回错误
            if (needle == NULL) {
                return 0;
            }
            // 获取needle和haystack在当前扫描点的颜色
            // 进行比较,看是否被修改
            if(old_needle != needle || old_haystack != haystack){
                // 如果 needle 或者 haystack 已被修改,返回0
                return 0;
            }

还是未能解决该问题

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

No branches or pull requests

1 participant