fix:mumuipc内存泄漏,提高内存利用率
This commit is contained in:
parent
13e84a09f0
commit
17d1fd919f
1 changed files with 7 additions and 4 deletions
|
@ -48,6 +48,7 @@ class MuMu12IPC:
|
||||||
self.instanse_index = int(config.conf.emulator.index)
|
self.instanse_index = int(config.conf.emulator.index)
|
||||||
self.connection = 0
|
self.connection = 0
|
||||||
self.display_id = -1
|
self.display_id = -1
|
||||||
|
self.pixels = (ctypes.c_ubyte * 8294400)()
|
||||||
# 加载动态链接库
|
# 加载动态链接库
|
||||||
dll_path = os.path.join(
|
dll_path = os.path.join(
|
||||||
self.emulator_folder, "sdk", "external_renderer_ipc.dll"
|
self.emulator_folder, "sdk", "external_renderer_ipc.dll"
|
||||||
|
@ -170,22 +171,24 @@ class MuMu12IPC:
|
||||||
|
|
||||||
def capture_display(self) -> np.ndarray:
|
def capture_display(self) -> np.ndarray:
|
||||||
self.check_status()
|
self.check_status()
|
||||||
pixels = (ctypes.c_ubyte * 8294400)()
|
|
||||||
result = self.external_renderer.nemu_capture_display(
|
result = self.external_renderer.nemu_capture_display(
|
||||||
self.connection,
|
self.connection,
|
||||||
self.display_id,
|
self.display_id,
|
||||||
8294400,
|
8294400,
|
||||||
ctypes.byref(ctypes.c_int(1920)),
|
ctypes.byref(ctypes.c_int(1920)),
|
||||||
ctypes.byref(ctypes.c_int(1080)),
|
ctypes.byref(ctypes.c_int(1080)),
|
||||||
pixels,
|
self.pixels,
|
||||||
)
|
)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
|
logger.error(f"获取截图失败: {result}")
|
||||||
self.connection = 0
|
self.connection = 0
|
||||||
self.display_id = -1
|
self.display_id = -1
|
||||||
config.device.exit() # 可能是游戏卡死
|
config.device.exit() # 可能是游戏卡死
|
||||||
return self.capture_display()
|
return np.zeros((1080, 1920, 3), dtype=np.uint8)
|
||||||
|
|
||||||
image = np.frombuffer(pixels, dtype=np.uint8).reshape((1080, 1920, 4))[:, :, :3]
|
image = np.frombuffer(self.pixels, dtype=np.uint8).reshape((1080, 1920, 4))[
|
||||||
|
:, :, :3
|
||||||
|
]
|
||||||
image = np.flipud(image) # 翻转
|
image = np.flipud(image) # 翻转
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue