Skip to content

Commit cbbd48d

Browse files
committed
feat(game): 优化FPS显示功能的线程管理
- 添加fpsThread成员变量用于管理FPS监控线程 - 将FPS获取逻辑从IO调度器改为独立线程执行 - 在while循环中添加线程中断检查防止内存泄漏 - 设置线程名称为"FCL FPS Thread"便于调试 - 正确启动和中断FPS线程确保资源释放 - 添加空指针检查避免异常情况
1 parent 029c60d commit cbbd48d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

FCL/src/main/java/com/tungsten/fcl/control/GameMenu.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public class GameMenu implements MenuCallback, View.OnClickListener {
139139
private TouchController touchController;
140140

141141
private boolean gamepadDisabled = false;
142+
private Thread fpsThread;
142143

143144
public void setMenuView(MenuView menuView) {
144145
this.menuView = menuView;
@@ -441,17 +442,23 @@ private void initRightMenu() {
441442
return;
442443
}
443444
if (isChecked) {
444-
Schedulers.io().execute(() -> {
445+
fpsThread = new Thread(() -> {
445446
FCLBridge.getFps();
446-
while (showFps.isChecked()) {
447+
while (showFps.isChecked() && !Thread.currentThread().isInterrupted()) {
447448
Schedulers.androidUIThread().execute(() -> fpsText.setText("FPS:" + FCLBridge.getFps()));
448449
try {
449450
Thread.sleep(1000);
450451
} catch (InterruptedException ignored) {
451452
}
452453
}
453454
});
455+
fpsThread.setName("FCL FPS Thread");
456+
fpsThread.start();
454457
} else {
458+
if (fpsThread != null) {
459+
fpsThread.interrupt();
460+
fpsThread = null;
461+
}
455462
fpsText.setText("");
456463
}
457464
});

0 commit comments

Comments
 (0)