Asset-Frameworker/Tickets/Resolved/BUG-GUI-PreviewToggleCrash.md
2025-04-29 18:26:13 +02:00

4.0 KiB

BUG: GUI - Persistent Crash When Toggling "Disable Detailed Preview"

Ticket Type: Bug Priority: High Status: Resolved

Description: The GUI application crashes with a Fatal Python error: _PyThreadState_Attach: non-NULL old thread state when toggling the "Disable Detailed Preview" option in the View menu. This issue persisted despite attempted fixes aimed at resolving potential threading conflicts.

This was a follow-up to a previous ticket regarding the "Disable Detailed Preview" feature regression (refer to ISSUE-GUI-DisableDetailedPreview-Regression.md). While the initial fix addressed the preview display logic, it did not eliminate the crash.

Symptoms: The application terminates unexpectedly with the fatal Python error traceback when the "Disable Detailed Preview" menu item is toggled on or off, particularly after assets have been added to the queue and the detailed preview has been generated or is in the process of being generated.

Steps to Reproduce:

  1. Launch the GUI (python -m gui.main_window).
  2. (Optional but recommended for diagnosis) Check the "Verbose Logging (DEBUG)" option in the View menu.
  3. Add one or more asset files (ZIPs or folders) to the drag and drop area.
  4. Wait for the detailed preview to populate (or start populating).
  5. Toggle the "Disable Detailed Preview" option in the View menu. The crash should occur.
  6. Toggle the option again if the first toggle didn't cause the crash.

Attempted Fixes:

  1. Modified gui/preview_table_model.py to introduce a _simple_mode flag and set_simple_mode method to control the data and column presentation for detailed vs. simple views.
  2. Modified gui/main_window.py (update_preview method) to:
    • Utilize the PreviewTableModel.set_simple_mode method based on the "Disable Detailed Preview" menu action state.
    • Configure the QTableView's column visibility and resize modes according to the selected preview mode.
    • Request cancellation of the PredictionHandler via prediction_handler.request_cancel() if it is running when update_preview is called. (Note: request_cancel did not exist in PredictionHandler).
  3. Added extensive logging with timestamps and thread IDs to gui/main_window.py, gui/preview_table_model.py, and gui/prediction_handler.py to diagnose threading behavior.

Diagnosis: Analysis of logs revealed that the crash occurred consistently when toggling the preview back ON, specifically during the endResetModel call within PreviewTableModel.set_simple_mode(False). The root cause was identified as a state inconsistency in the QTableView (or associated models) caused by a redundant call to PreviewTableModel.set_data immediately following PreviewTableModel.set_simple_mode(True) within the MainWindow.update_preview method when switching to simple mode. This resulted in two consecutive beginResetModel/endResetModel calls on the main thread, leaving the model/view in an unstable state that triggered the crash on the subsequent toggle. Additionally, it was found that PredictionHandler lacked a request_cancel method, although this was not the direct cause of the crash.

Resolution:

  1. Removed the redundant call to self.preview_model.set_data(list(self.current_asset_paths)) within the if simple_mode_enabled: block in MainWindow.update_preview. The set_simple_mode(True) call is sufficient to switch the model's internal mode.
  2. Added an explicit call to self.preview_model.set_data(list(self.current_asset_paths)) within the MainWindow.add_input_paths method, specifically for the case when the GUI is in simple preview mode. This ensures the simple view is updated correctly when new files are added without relying on the problematic set_data call in update_preview.
  3. Corrected instances of QThread.currentThreadId() to QThread.currentThread() in logging statements across the relevant files.
  4. Added the missing QThread import in gui/prediction_handler.py.

Relevant Files/Components:

  • gui/main_window.py
  • gui/preview_table_model.py
  • gui/prediction_handler.py