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:
- Launch the GUI (
python -m gui.main_window). - (Optional but recommended for diagnosis) Check the "Verbose Logging (DEBUG)" option in the View menu.
- Add one or more asset files (ZIPs or folders) to the drag and drop area.
- Wait for the detailed preview to populate (or start populating).
- Toggle the "Disable Detailed Preview" option in the View menu. The crash should occur.
- Toggle the option again if the first toggle didn't cause the crash.
Attempted Fixes:
- Modified
gui/preview_table_model.pyto introduce a_simple_modeflag andset_simple_modemethod to control the data and column presentation for detailed vs. simple views. - Modified
gui/main_window.py(update_previewmethod) to:- Utilize the
PreviewTableModel.set_simple_modemethod 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
PredictionHandlerviaprediction_handler.request_cancel()if it is running whenupdate_previewis called. (Note:request_canceldid not exist inPredictionHandler).
- Utilize the
- Added extensive logging with timestamps and thread IDs to
gui/main_window.py,gui/preview_table_model.py, andgui/prediction_handler.pyto 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:
- Removed the redundant call to
self.preview_model.set_data(list(self.current_asset_paths))within theif simple_mode_enabled:block inMainWindow.update_preview. Theset_simple_mode(True)call is sufficient to switch the model's internal mode. - Added an explicit call to
self.preview_model.set_data(list(self.current_asset_paths))within theMainWindow.add_input_pathsmethod, 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 problematicset_datacall inupdate_preview. - Corrected instances of
QThread.currentThreadId()toQThread.currentThread()in logging statements across the relevant files. - Added the missing
QThreadimport ingui/prediction_handler.py.
Relevant Files/Components:
gui/main_window.pygui/preview_table_model.pygui/prediction_handler.py