mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-16 03:33:25 +08:00
[全自动地脉花]: 修复地脉花OCR识别内存泄漏问题 (#2433)
* fix(js): 修复地脉花OCR识别内存泄漏问题 将resList变量声明移至try块外部,并在finally块中统一释放资源,避免多处dispose调用导致的内存管理问题 * update version 4.4.5 * fix(js): 修复浓缩树脂OCR识别内存泄漏问题 将textList变量声明移至try块外部,并在finally块中统一释放OCR识别结果资源,避免多处dispose调用导致的内存管理问题 * fix(js): 修复地脉花OCR识别captureRegion内存泄漏问题 将captureRegion变量声明移至try块外部,并在finally块中添加资源释放,避免captureGameRegion()调用产生的内存泄漏
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "全自动地脉花",
|
||||
"version": "4.4.4",
|
||||
"version": "4.4.5",
|
||||
"tags": ["地脉花"],
|
||||
"bgi_version": "0.52.0",
|
||||
"description": "基于OCR图像识别的全自动刷取地脉花。\n💡更多信息请查看README! \n\n----------注意事项----------\n●仅支持BetterGI 0.52.0 及以上版本!\n●部分地脉花因特殊原因不支持全自动,具体的点位请在手册中查看。\n●树脂使用的优先级:2倍原粹树脂 > 浓缩树脂 > 原粹树脂。\n●运行时会传送到七天神像设置中设置的七天神像,需要关闭七天神像设置中的“是否就近七天神像恢复血量”,并指定七天神像。\n●战斗策略注意调度器设置中地图追踪行走配置里的“允许在JsSpript中使用”和“覆盖JS中的自动战斗配置”,只有在都打开的情况下脚本才会使用下面的战斗配置,否则会使用独立任务中的战斗策略。战斗超时时间不能大于脚本自定义配置中的时间。\n\n如果遇到问题,请先参照README中的方法进行解决。",
|
||||
|
||||
@@ -156,20 +156,20 @@ function isPointInRegion(point, region) {
|
||||
* @returns {number|null} 识别到的数字或null
|
||||
*/
|
||||
async function recognizeNumberByOCR(ocrRegion, pattern) {
|
||||
let resList = null;
|
||||
let captureRegion = null;
|
||||
try {
|
||||
// 直接链式调用,避免内存管理问题
|
||||
const ocrRo = RecognitionObject.ocr(ocrRegion.x, ocrRegion.y, ocrRegion.width, ocrRegion.height);
|
||||
const resList = captureGameRegion().findMulti(ocrRo);
|
||||
captureRegion = captureGameRegion();
|
||||
resList = captureRegion.findMulti(ocrRo);
|
||||
|
||||
if (!resList || resList.length === 0) {
|
||||
log.warn("OCR未识别到任何文本");
|
||||
resList.dispose();
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const res of resList) {
|
||||
if (!res || !res.text) {
|
||||
resList.dispose();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -177,17 +177,22 @@ async function recognizeNumberByOCR(ocrRegion, pattern) {
|
||||
if (numberMatch) {
|
||||
const number = parseInt(numberMatch[1] || numberMatch[0]);
|
||||
if (!isNaN(number)) {
|
||||
resList.dispose();
|
||||
return number;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
log.error(`OCR识别时发生异常: ${error.message}`);
|
||||
resList.dispose();
|
||||
return null;
|
||||
} finally {
|
||||
if (resList && typeof resList.dispose === 'function') {
|
||||
resList.dispose();
|
||||
}
|
||||
if (captureRegion && typeof captureRegion.dispose === 'function') {
|
||||
captureRegion.dispose();
|
||||
}
|
||||
}
|
||||
resList.dispose();
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== 树脂计数函数 ====================
|
||||
@@ -258,22 +263,30 @@ async function countCondensedResin() {
|
||||
// 点击浓缩树脂打开说明界面统计
|
||||
condensedResin.click();
|
||||
await sleep(CONFIG.UI_DELAY);
|
||||
let captureRegion = captureGameRegion();
|
||||
// OCR识别整个界面的文本
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, captureRegion.width, captureRegion.height);
|
||||
let textList = captureRegion.findMulti(ocrRo);
|
||||
captureRegion.dispose();
|
||||
for (const res of textList) {
|
||||
if (res.text.includes("当前拥有")) {
|
||||
const match = res.text.match(/当前拥有\s*([0-5ss])/);
|
||||
if (match && match[1]) {
|
||||
const count = parseInt(match[1]);
|
||||
log.info(`浓缩树脂数量(说明界面): ${count}`);
|
||||
keyPress("ESCAPE");
|
||||
await sleep(CONFIG.UI_DELAY);
|
||||
return count;
|
||||
let captureRegion = captureGameRegion();
|
||||
let textList = null;
|
||||
try {
|
||||
// OCR识别整个界面的文本
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, captureRegion.width, captureRegion.height);
|
||||
textList = captureRegion.findMulti(ocrRo);
|
||||
|
||||
for (const res of textList) {
|
||||
if (res.text.includes("当前拥有")) {
|
||||
const match = res.text.match(/当前拥有\s*([0-5ss])/);
|
||||
if (match && match[1]) {
|
||||
const count = parseInt(match[1]);
|
||||
log.info(`浓缩树脂数量(说明界面): ${count}`);
|
||||
keyPress("ESCAPE");
|
||||
await sleep(CONFIG.UI_DELAY);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (textList && typeof textList.dispose === 'function') {
|
||||
textList.dispose();
|
||||
}
|
||||
captureRegion.dispose();
|
||||
}
|
||||
|
||||
log.warn(`未能识别浓缩树脂数量`);
|
||||
|
||||
Reference in New Issue
Block a user