From cef3eb3297451f088ca5618c2b44aa858b2fa5b1 Mon Sep 17 00:00:00 2001 From: Summer <71572746+SummerSigh@users.noreply.github.com> Date: Sun, 13 Apr 2025 12:00:29 -0700 Subject: [PATCH] push fix --- BabbleApp/babbleapp.py | 2 ++ BabbleApp/camera.py | 18 +++++++++++++++++- .../vivefacialtracker/camera_controller.py | 4 +++- scripts/build_app_and_installer.bat | 2 +- scripts/installer.iss | 10 +++++----- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/BabbleApp/babbleapp.py b/BabbleApp/babbleapp.py index f1a3263..a394b06 100644 --- a/BabbleApp/babbleapp.py +++ b/BabbleApp/babbleapp.py @@ -299,11 +299,13 @@ async def async_main(): ROSC = True # Create the window + # Use finalize=True to ensure the window is created only once window = sg.Window( f"{AppConstants.VERSION}", layout, icon=os.path.join("Images", "logo.ico"), background_color=bg_color_clear, + finalize=True ) # Run the main loop diff --git a/BabbleApp/camera.py b/BabbleApp/camera.py index 1c425e1..5955f49 100644 --- a/BabbleApp/camera.py +++ b/BabbleApp/camera.py @@ -214,8 +214,24 @@ class Camera: if image is None: return self.frame_number = self.frame_number + 1 + # Ensure we have a valid image for cropping mode + if image.size == 0: + print(f'{Fore.YELLOW}[{lang._instance.get_string("log.warn")}] Empty frame from VFT camera{Fore.RESET}') + return elif self.cv2_camera is not None and self.cv2_camera.isOpened(): - ret, image = self.cv2_camera.read() # MJPEG Stream reconnects are currently limited by the hard coded 30 second timeout time on VideoCapture.read(). We can get around this by recompiling OpenCV or using a custom MJPEG stream imp. + # Implement a timeout mechanism to prevent hanging on MJPEG streams + start_time = time.time() + ret, image = self.cv2_camera.read() # MJPEG Stream reconnects are currently limited by the hard coded 30 second timeout time on VideoCapture.read(). + # If read takes too long, reset the connection + if time.time() - start_time > 5: # 5 second timeout instead of waiting for 30 seconds + print(f'{Fore.YELLOW}[{lang._instance.get_string("log.warn")}] MJPEG stream timeout, reconnecting...{Fore.RESET}') + self.cv2_camera.release() + if self.config.use_ffmpeg: + self.cv2_camera = cv2.VideoCapture(self.current_capture_source, cv2.CAP_FFMPEG) + else: + self.cv2_camera = cv2.VideoCapture() + self.cv2_camera.open(self.current_capture_source) + ret, image = self.cv2_camera.read() if not ret: self.cv2_camera.set(cv2.CAP_PROP_POS_FRAMES, 0) raise RuntimeError(lang._instance.get_string("error.frame")) diff --git a/BabbleApp/vivefacialtracker/camera_controller.py b/BabbleApp/vivefacialtracker/camera_controller.py index 2f6aef0..fdacc38 100644 --- a/BabbleApp/vivefacialtracker/camera_controller.py +++ b/BabbleApp/vivefacialtracker/camera_controller.py @@ -72,7 +72,9 @@ class FTCameraController: self.is_open = True FTCameraController._logger.info("FTCameraController.open: start process") self._proc_queue = multiprocessing.Queue(maxsize=1) - self._proc_read = multiprocessing.Process(target=self._read_process, args=(self._proc_queue,)) + # Set daemon=True to ensure the process terminates when the main process exits + # This helps prevent spawning multiple GUI windows in PyInstaller builds + self._proc_read = multiprocessing.Process(target=self._read_process, args=(self._proc_queue,), daemon=True) self._proc_read.start() def _reopen(self: 'FTCameraController') -> None: diff --git a/scripts/build_app_and_installer.bat b/scripts/build_app_and_installer.bat index 2294d3d..84cc3c3 100644 --- a/scripts/build_app_and_installer.bat +++ b/scripts/build_app_and_installer.bat @@ -1,6 +1,6 @@ :: File paths will all need to be updated to your setup -set babblepath=C:\Documents\GitHub\ProjectBabble +set babblepath=C:\Users\sameer\Documents\GitHub\ProjectBabble set innopath="C:\Program Files (x86)\Inno Setup 6" cd /d %babblepath%\BabbleApp diff --git a/scripts/installer.iss b/scripts/installer.iss index f29b075..4a36453 100644 --- a/scripts/installer.iss +++ b/scripts/installer.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "Project Babble" -#define MyAppVersion "2.0.7" +#define MyAppVersion "2.1.5 Beta Build" #define MyAppPublisher "Project Babble Team" #define MyAppURL "https://github.com/Project-Babble/ProjectBabble" #define MyAppExeName "Babble_App.exe" @@ -20,11 +20,11 @@ AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={autopf}\{#MyAppName} DisableProgramGroupPage=yes -OutputDir=C:\Users\epicm\OneDrive\Desktop\build +OutputDir=C:\Users\sameer\OneDrive\Desktop\build ; Uncomment the following line to run in non administrative install mode (install for current user only.) ;PrivilegesRequired=lowest OutputBaseFilename=Project_Babble-Setup -SetupIconFile=C:\Documents\GitHub\ProjectBabble\BabbleApp\Images\logo.ico +SetupIconFile=C:\Users\sameer\Documents\GitHub\ProjectBabble\BabbleApp\Images\logo.ico Compression=lzma/ultra64 SolidCompression=yes @@ -40,8 +40,8 @@ Name: "english"; MessagesFile: "compiler:Default.isl" Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; [Files] -Source: "C:\Documents\GitHub\ProjectBabble\BabbleApp\dist\Babble_App\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion -Source: "C:\Documents\GitHub\ProjectBabble\BabbleApp\dist\Babble_App\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "C:\Users\sameer\Documents\GitHub\ProjectBabble\BabbleApp\dist\Babble_App\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +Source: "C:\Users\sameer\Documents\GitHub\ProjectBabble\BabbleApp\dist\Babble_App\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Dirs]