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

22 lines
8.4 KiB
JSON

{
"sourceFile": "Tickets/BUG-GUI-PreviewToggleCrash.md",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 1,
"patches": [
{
"date": 1745332803099,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1745333909377,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,13 +1,14 @@\n # BUG: GUI - Persistent Crash When Toggling \"Disable Detailed Preview\"\r\n \r\n **Ticket Type:** Bug\r\n **Priority:** High\r\n+**Status:** Resolved\r\n \r\n **Description:**\r\n-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 persists despite attempted fixes aimed at resolving potential threading conflicts.\r\n+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.\r\n \r\n-This is 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.\r\n+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.\r\n \r\n **Symptoms:**\r\n 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.\r\n \r\n@@ -23,13 +24,20 @@\n 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.\r\n 2. Modified `gui/main_window.py` (`update_preview` method) to:\r\n * Utilize the `PreviewTableModel.set_simple_mode` method based on the \"Disable Detailed Preview\" menu action state.\r\n * Configure the `QTableView`'s column visibility and resize modes according to the selected preview mode.\r\n- * Request cancellation of the `PredictionHandler` via `prediction_handler.request_cancel()` if it is running when `update_preview` is called.\r\n+ * 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`).\r\n+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.\r\n \r\n-**Hypothesis:**\r\n-The crash is likely still a threading conflict between the main UI thread (resetting the model via `beginResetModel`/`endResetModel` in `set_simple_mode`) and the prediction thread (potentially still interacting with the model or its underlying data structure after a cancellation request, or due to a signal/slot timing issue). The cancellation mechanism in `PredictionHandler` might not be immediately effective or might not fully prevent all potential race conditions during model reset.\r\n+**Diagnosis:**\r\n+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.\r\n \r\n+**Resolution:**\r\n+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.\r\n+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`.\r\n+3. Corrected instances of `QThread.currentThreadId()` to `QThread.currentThread()` in logging statements across the relevant files.\r\n+4. Added the missing `QThread` import in `gui/prediction_handler.py`.\r\n+\r\n **Relevant Files/Components:**\r\n * `gui/main_window.py`\r\n * `gui/preview_table_model.py`\r\n * `gui/prediction_handler.py`\n\\ No newline at end of file\n"
}
],
"date": 1745332803099,
"name": "Commit-0",
"content": "# BUG: GUI - Persistent Crash When Toggling \"Disable Detailed Preview\"\r\n\r\n**Ticket Type:** Bug\r\n**Priority:** High\r\n\r\n**Description:**\r\nThe 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 persists despite attempted fixes aimed at resolving potential threading conflicts.\r\n\r\nThis is 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.\r\n\r\n**Symptoms:**\r\nThe 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.\r\n\r\n**Steps to Reproduce:**\r\n1. Launch the GUI (`python -m gui.main_window`).\r\n2. (Optional but recommended for diagnosis) Check the \"Verbose Logging (DEBUG)\" option in the View menu.\r\n3. Add one or more asset files (ZIPs or folders) to the drag and drop area.\r\n4. Wait for the detailed preview to populate (or start populating).\r\n5. Toggle the \"Disable Detailed Preview\" option in the View menu. The crash should occur.\r\n6. Toggle the option again if the first toggle didn't cause the crash.\r\n\r\n**Attempted Fixes:**\r\n1. 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.\r\n2. Modified `gui/main_window.py` (`update_preview` method) to:\r\n * Utilize the `PreviewTableModel.set_simple_mode` method based on the \"Disable Detailed Preview\" menu action state.\r\n * Configure the `QTableView`'s column visibility and resize modes according to the selected preview mode.\r\n * Request cancellation of the `PredictionHandler` via `prediction_handler.request_cancel()` if it is running when `update_preview` is called.\r\n\r\n**Hypothesis:**\r\nThe crash is likely still a threading conflict between the main UI thread (resetting the model via `beginResetModel`/`endResetModel` in `set_simple_mode`) and the prediction thread (potentially still interacting with the model or its underlying data structure after a cancellation request, or due to a signal/slot timing issue). The cancellation mechanism in `PredictionHandler` might not be immediately effective or might not fully prevent all potential race conditions during model reset.\r\n\r\n**Relevant Files/Components:**\r\n* `gui/main_window.py`\r\n* `gui/preview_table_model.py`\r\n* `gui/prediction_handler.py`"
}
]
}