From 10e9f43ee9b0998a904aa37bb629d1504afe7a96 Mon Sep 17 00:00:00 2001 From: SnuffSocket <82658601+SnuffSocket@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:12:32 +0300 Subject: [PATCH 1/3] Fix: Crash "GUI off mem leak, frame buildup" By RedHawk989: https://github.com/EyeTrackVR/EyeTrackVR/commit/df29fc0380ace8845ca91f4bf1ae426244525653 --- BabbleApp/babble_processor.py | 25 ++++++++++++------------- BabbleApp/babbleapp.py | 2 +- BabbleApp/landmark_processor.py | 27 +++++++++++++-------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/BabbleApp/babble_processor.py b/BabbleApp/babble_processor.py index 2eddb4c..837acb9 100644 --- a/BabbleApp/babble_processor.py +++ b/BabbleApp/babble_processor.py @@ -111,20 +111,19 @@ class BabbleProcessor: ) def output_images_and_update(self, output_information: CamInfo): - try: - image_stack = np.concatenate( - ( - cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), - ), - axis=1, - ) - self.image_queue_outgoing.put((image_stack, output_information)) - self.previous_image = self.current_image - self.previous_rotation = self.config.rotation_angle - except: # If this fails it likely means that the images are not the same size for some reason. - print('\033[91m[ERROR] Size of frames to display are of unequal sizes.\033[0m') + image_stack = np.concatenate( + ( + cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), + ), + axis=1, + ) + self.image_queue_outgoing.put((image_stack, output_information)) + if self.image_queue_outgoing.qsize() > 1: + self.image_queue_outgoing.get() + + self.previous_image = self.current_image + self.previous_rotation = self.config.rotation_angle - pass def capture_crop_rotate_image(self): # Get our current frame diff --git a/BabbleApp/babbleapp.py b/BabbleApp/babbleapp.py index e979dcd..f990d63 100644 --- a/BabbleApp/babbleapp.py +++ b/BabbleApp/babbleapp.py @@ -98,7 +98,7 @@ def main(): # Check to see if we have an ROI. If not, bring up ROI finder GUI. # Spawn worker threads - osc_queue: queue.Queue[tuple[bool, int, int]] = queue.Queue(maxsize=2) + osc_queue: queue.Queue[tuple[bool, int, int]] = queue.Queue(maxsize=10) osc = VRChatOSC(cancellation_event, osc_queue, config) osc_thread = threading.Thread(target=osc.run) # start worker threads diff --git a/BabbleApp/landmark_processor.py b/BabbleApp/landmark_processor.py index d642a47..3470161 100644 --- a/BabbleApp/landmark_processor.py +++ b/BabbleApp/landmark_processor.py @@ -114,25 +114,24 @@ class LandmarkProcessor: def get_frame(self): return self.current_image_gray_clean - + def infer_frame(self, image): return write_image(self, image) def output_images_and_update(self, output_information: CamInfo): - try: - image_stack = np.concatenate( - ( - cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), - ), - axis=1, - ) - self.image_queue_outgoing.put((image_stack, output_information)) - self.previous_image = self.current_image - self.previous_rotation = self.config.rotation_angle - except: # If this fails it likely means that the images are not the same size for some reason. - print('\033[91m[ERROR] Size of frames to display are of unequal sizes.\033[0m') + image_stack = np.concatenate( + ( + cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), + ), + axis=1, + ) + self.image_queue_outgoing.put((image_stack, output_information)) + if self.image_queue_outgoing.qsize() > 1: + self.image_queue_outgoing.get() + + self.previous_image = self.current_image + self.previous_rotation = self.config.rotation_angle - pass def capture_crop_rotate_image(self): # Get our current frame From 66221f1cac53baeb1c00ef107c3b0856850d7809 Mon Sep 17 00:00:00 2001 From: SnuffSocket <82658601+SnuffSocket@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:18:12 +0300 Subject: [PATCH 2/3] Feat: Lower CPU usage when not in focus by stopping 'n slowing down the GUI loop. --- BabbleApp/babbleapp.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/BabbleApp/babbleapp.py b/BabbleApp/babbleapp.py index f990d63..3c25710 100644 --- a/BabbleApp/babbleapp.py +++ b/BabbleApp/babbleapp.py @@ -17,6 +17,7 @@ Copyright (c) 2023 Project Babble <3 ''' import os +import time import PySimpleGUI as sg import queue import requests @@ -222,6 +223,14 @@ def main(): print("\033[94m[INFO] Exiting BabbleApp\033[0m") return + # When focus is lost stop 'n slow down the loop here. + try: + if not window.TKroot.focus_get(): + time.sleep(0.2) + continue + except KeyError: + pass + if values[CAM_RADIO_NAME] and config.cam_display_id != Tab.CAM: cams[0].start() settings[0].stop() From 2cf8234ad4eaa965efbcec85d5c66b48d448d3a5 Mon Sep 17 00:00:00 2001 From: SnuffSocket <82658601+SnuffSocket@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:34:16 +0300 Subject: [PATCH 3/3] Fix: Made intended behavior more clear to the user --- BabbleApp/Locale/English/locale.json | 1 + BabbleApp/Locale/OwO/locale.json | 1 + BabbleApp/Locale/Pirate Speak/locale.json | 1 + BabbleApp/babbleapp.py | 24 ++++++++++++++++++----- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/BabbleApp/Locale/English/locale.json b/BabbleApp/Locale/English/locale.json index f83df1c..70233d3 100644 --- a/BabbleApp/Locale/English/locale.json +++ b/BabbleApp/Locale/English/locale.json @@ -16,6 +16,7 @@ "general.recalibrate": "Recalibrate Address", "general.recalibrateTooltip": "OSC address we use for recalibrating", "general.uvcCameraSettings": "UVC Camera Settings", + "general.windowFocus": "Interface Paused", "general.useRedChannel": "Use Red Channel", "general.useRedChannelTooltip": "Uses only the red channel for Omnicept capture", "general.xResolution": "X Resolution", diff --git a/BabbleApp/Locale/OwO/locale.json b/BabbleApp/Locale/OwO/locale.json index 92db42f..1995b33 100644 --- a/BabbleApp/Locale/OwO/locale.json +++ b/BabbleApp/Locale/OwO/locale.json @@ -16,6 +16,7 @@ "general.recalibrate": "Wecawibwate Addwess :3", "general.recalibrateTooltip": "OSC addwess we use fow wecawibwating OwO", "general.uvcCameraSettings": "UVC Camewa Settings UwU", + "general.windowFocus": "Intwaface Pawused", "general.useRedChannel": "Use Wed Channew >w<", "general.useRedChannelTooltip": "Uses onwy the wed channew fow Omnicept captuwe nya~", "general.xResolution": "X Wesowution :3", diff --git a/BabbleApp/Locale/Pirate Speak/locale.json b/BabbleApp/Locale/Pirate Speak/locale.json index e72d220..280b5de 100644 --- a/BabbleApp/Locale/Pirate Speak/locale.json +++ b/BabbleApp/Locale/Pirate Speak/locale.json @@ -16,6 +16,7 @@ "general.recalibrate": "Recalibrate Yer Bearings", "general.recalibrateTooltip": "OSC bearings we use fer recalibratin'", "general.uvcCameraSettings": "Spyglass Settings", + "general.windowFocus": "Interfayce Be Paused", "general.useRedChannel": "Use th' Red Channel", "general.useRedChannelTooltip": "Uses only th' red channel fer Omnicept plunderin'", "general.xResolution": "X Marks th' Spot", diff --git a/BabbleApp/babbleapp.py b/BabbleApp/babbleapp.py index 5012dc7..9bec103 100644 --- a/BabbleApp/babbleapp.py +++ b/BabbleApp/babbleapp.py @@ -17,7 +17,6 @@ Copyright (c) 2023 Project Babble <3 """ import os -import time import PySimpleGUI as sg import queue import requests @@ -207,6 +206,8 @@ def main(): background_color=bg_color_highlight, ), ], + # Keep at bottom! + [sg.Text(f'- - - {lang._instance.get_string("general.windowFocus")} - - -', key="-WINFOCUS-", background_color=bg_color_clear, text_color="#F0F0F0", justification="center", expand_x=True, visible=False)], ] if config.cam_display_id in [Tab.CAM]: @@ -230,10 +231,12 @@ def main(): f"{appversion}", layout, icon="Images/logo.ico", background_color=bg_color_clear ) + tint = 33 + fs = False # GUI Render loop while True: # First off, check for any events from the GUI - event, values = window.read(timeout=30) + event, values = window.read(timeout=tint) # If we're in either mode and someone hits q, quit immediately if event in ("Exit", sg.WIN_CLOSED): @@ -259,10 +262,21 @@ def main(): ) return - # When focus is lost stop 'n slow down the loop here. try: - if not window.TKroot.focus_get(): - time.sleep(0.2) + # If window isn't in focus increase timeout and stop loop early + if window.TKroot.focus_get(): + if fs: + fs = False + tint = 33 + window["-WINFOCUS-"].update(visible=False) + window["-WINFOCUS-"].hide_row() + window.refresh() + else: + if not fs: + fs = True + tint = 100 + window["-WINFOCUS-"].update(visible=True) + window["-WINFOCUS-"].unhide_row() continue except KeyError: pass