Skip to content

Commit 8e103e8

Browse files
authored
fix(python): 修复 Context.wait_freezes 的 Rect 句柄传递,改用 RectBuffer 管理 (#1175)
1 parent ec3abe3 commit 8e103e8

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

source/binding/Python/maa/context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,21 +446,22 @@ def wait_freezes(
446446
Note:
447447
- time 和 wait_freezes_param.time 互斥,不能同时为非零或同时为零 / time and wait_freezes_param.time are mutually exclusive
448448
"""
449-
rect_handle = None
449+
rect_buffer = None
450450
if box:
451-
rect_handle = MaaRectHandle()
452-
Library.framework().MaaRectSet(rect_handle, box[0], box[1], box[2], box[3])
451+
rect_buffer = RectBuffer()
452+
rect_buffer.set(box)
453453

454454
# Convert JWaitFreezes to dict
455455
from dataclasses import asdict
456+
456457
param_dict = asdict(wait_freezes_param) if wait_freezes_param is not None else {}
457458
param_json = json.dumps(param_dict, ensure_ascii=False)
458459

459460
return bool(
460461
Library.framework().MaaContextWaitFreezes(
461462
self._handle,
462463
ctypes.c_uint64(time),
463-
rect_handle,
464+
rect_buffer._handle if rect_buffer else None,
464465
param_json.encode(),
465466
)
466467
)

test/python/binding_test.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,20 @@ def analyze(
154154
# 测试 wait_freezes API(参数校验:time 和 wait_freezes_param.time 同时为零应返回 false)
155155
from maa.pipeline import JWaitFreezes
156156

157-
wait_result = new_ctx.wait_freezes(
158-
time=0, wait_freezes_param=JWaitFreezes(time=0)
159-
)
160-
print(f" wait_freezes (both zero): {wait_result}")
161-
assert (
162-
not wait_result
163-
), "wait_freezes should return false when both time are zero"
157+
wait_cases = [
158+
("both zero", None),
159+
("both zero, with box", (10, 10, 100, 100)),
160+
]
161+
for case_name, box in wait_cases:
162+
wait_result = new_ctx.wait_freezes(
163+
time=0,
164+
box=box,
165+
wait_freezes_param=JWaitFreezes(time=0),
166+
)
167+
print(f" wait_freezes ({case_name}): {wait_result}")
168+
assert (
169+
not wait_result
170+
), "wait_freezes should return false when both time are zero"
164171

165172
# 测试 override_image
166173
test_image = numpy.zeros((100, 100, 3), dtype=numpy.uint8)
@@ -218,7 +225,9 @@ def run(
218225
uuid = controller.uuid
219226
resolution = controller.resolution
220227
info = controller.info
221-
print(f" connected: {connected}, uuid: {uuid}, resolution: {resolution}, info type: {info.get('type')}")
228+
print(
229+
f" connected: {connected}, uuid: {uuid}, resolution: {resolution}, info type: {info.get('type')}"
230+
)
222231

223232
global runned
224233
runned = True
@@ -398,7 +407,9 @@ def test_controller_api():
398407
print(f" info: {info}")
399408
assert isinstance(info, dict), "info should be a dict"
400409
assert "type" in info, "info should contain 'type'"
401-
assert info["type"].startswith("dbg_"), "dbg controller type should start with 'dbg_'"
410+
assert info["type"].startswith(
411+
"dbg_"
412+
), "dbg controller type should start with 'dbg_'"
402413

403414
# 测试输入操作
404415
dbg_controller.post_click(100, 100).wait()
@@ -685,7 +696,9 @@ def test_custom_controller():
685696
print(f" info: {info}")
686697
assert isinstance(info, dict), "info should be a dict"
687698
assert info.get("type") == "custom", "info type should be custom"
688-
assert info.get("custom_key") == "custom_value", "custom info should contain custom_key"
699+
assert (
700+
info.get("custom_key") == "custom_value"
701+
), "custom info should contain custom_key"
689702
assert info.get("answer") == 42, "custom info should contain answer"
690703

691704
ret &= controller.post_start_app("custom_aaa").wait().succeeded

0 commit comments

Comments
 (0)