neko-para/maa-node

[bug] electron使用maa2.0版本的register_custom_recognizer报错

Night-stars-1 opened this issue · 2 comments

操作系统: win11
node: v20.15.1
maa-node: v2.0.0-alpha.3-post.4-ci.10860780438
electron来源: https://github.com/neko-para/maa-node-template
https://github.com/neko-para/maa-node/blob/main/doc/zh_cn/Package.md#maa-node-template
maa-log: maa.log

经测试,2.0版本使用register_custom_recognizer注册识别器后,后续任务如果使用了识别器,会报错

(node:9108) [DEP0168] DeprecationWarning: Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.

image
开启 --force-node-api-uncaught-exceptions-policy 后提示如下
image

  • 去掉electron单独运行,顺利运行
  • 去掉识别器部分,不去掉electron,顺利运行
  • maa-node来自这个action-10861041274

代码使用的是https://github.com/neko-para/maa-node/blob/d61e2aaab8980022ac2c9ebb3768dd3ac74bb6d4/sample/simpleLauncher.ts
await tskr.post_pipeline('StartUpAndClickButton')做了修改

const my_reco: maa.CustomRecognizerCallback = async self => {
    let reco_detail = await self.context.run_recognition('MyCustomOCR', self.image, {
        MyCustomOCR: {
            roi: [100, 100, 200, 300]
        }
    })

    self.context.override_pipeline({
        MyCustomOCR: {
            roi: [1, 1, 114, 514]
        }
    })

    const new_context = self.context.clone()
    new_context.override_pipeline({
        MyCustomOCR: {
            roi: [100, 200, 300, 400]
        }
    })

    reco_detail = await new_context.run_recognition('MyCustomOCR', self.image)

    const click_job = self.context.tasker.controller!.post_click(10, 20)
    await click_job.wait()

    self.context.override_next(self.task, ['TaskA', 'TaskB'])

    return [
        {
            x: 0,
            y: 0,
            width: 100,
            height: 100
        },
        'Hello World!'
    ]
}

async function main() {
    maa.Global.config_init_option('./')

    const res = new maa.Resource()
    res.notify = (msg, detail) => {
        console.log(msg, detail)
    }

    const devices = await maa.AdbController.find()
    if (!devices || devices.length === 0) {
        return
    }
    const [name, adb_path, address, screencap_methods, input_methods, config] = devices[0]
    const ctrl = new maa.AdbController(adb_path, address, screencap_methods, input_methods, config)
    ctrl.notify = (msg, detail) => {
        console.log(msg, detail)
    }
    await ctrl.post_connection().wait()

    const tskr = new maa.Tasker()
    tskr.notify = (msg, detail) => {
        console.log(msg, detail)
    }

    tskr.bind(ctrl)
    tskr.bind(res)

    console.log(tskr.inited)

    res.register_custom_recognizer('MyRec', my_reco)

    let task_detail = await tskr.post_pipeline('StartUpAndClickButton', {
      StartUpAndClickButton: {
        next: ['test']
      },
      test: {
        recognition: 'Custom',
        custom_recognition: 'MyRec',
        custom_recognition_param: {
          msg: 'Hello world!'
        }
      }
    }).wait().get()

    let reco_task_detail = await tskr.post_recognition('MySingleMatch').wait().get()

    tskr.destroy()
    ctrl.destroy()
    res.destroy()
}

main()

这个问题我好像知道原因,晚上我看看怎么换个实现