wmTimer, wmJob and WM_report issue - can lead to crash #105369

Closed
opened 2023-03-02 11:32:51 +01:00 by Bastien Montagne · 5 comments

The Problem

Report #105160 unveils a critical issue in wmTimer handling.

Essentially, in several places of WM code timers are looped over in that way:

/* Mutable in case the timer gets removed. */
LISTBASE_FOREACH_MUTABLE (wmTimer *, wt, &wm->timers) {
  ...
}

This is actually not working as expected, because during the processing of a wmTimer, other wmTimers may be added or removed and freed, The latter will lead to a crash if it is the next timer in the list (LISTBASE_FOREACH_MUTABLE only protects against removal/freeing of the current item).

The typical identified case if a job timer updating or ending its job, which job callbacks would call WM_report, which ends up removing/freeing a timer and adding a new one for the report 'popup' in the UI.

Proposed Solutions

This issue has potential solutions at several levels.

1. Simple Fix the Current Issue

The issue with WM_report modifying timers could be addressed by having a flag in the WindowManager marking timers as being processed, in which case WM_report (or more precisely wm_add_reports) should not call WM_report_banner_show.

WM_report_banner_show call could then be added at the end of the loops over wmTimer.

2. More General Fix

Making wmTimer loop safe in general could be achieved by deferring their deletion (tagging them to be deleted, and actually deleting them in a second, safe loop).

### The Problem Report #105160 unveils a critical issue in wmTimer handling. Essentially, in several places of WM code timers are looped over in that way: ``` /* Mutable in case the timer gets removed. */ LISTBASE_FOREACH_MUTABLE (wmTimer *, wt, &wm->timers) { ... } ``` This is actually not working as expected, because during the processing of a wmTimer, other wmTimers may be added or removed and freed, The latter will lead to a crash if it is the next timer in the list (`LISTBASE_FOREACH_MUTABLE` only protects against removal/freeing of the current item). The typical identified case if a job timer updating or ending its job, which job callbacks would call `WM_report`, which ends up removing/freeing a timer and adding a new one for the report 'popup' in the UI. ### Proposed Solutions This issue has potential solutions at several levels. #### 1. Simple Fix the Current Issue The issue with `WM_report` modifying timers could be addressed by having a flag in the WindowManager marking timers as being processed, in which case `WM_report` (or more precisely `wm_add_reports`) should not call `WM_report_banner_show`. `WM_report_banner_show` call could then be added at the end of the loops over wmTimer. #### 2. More General Fix Making wmTimer loop safe in general could be achieved by deferring their deletion (tagging them to be deleted, and actually deleting them in a second, safe loop).
Bastien Montagne added the
Type
Design
Module
Core
labels 2023-03-02 11:32:51 +01:00
Bastien Montagne added this to the 3.5 milestone 2023-03-02 11:33:04 +01:00
Author
Owner

@ideasman42 @brecht, could use your feedback on this one. Think it's a fairly bad issue, and would rather fix it for 3.5 (and backport to previous LTS)?

@ideasman42 @brecht, could use your feedback on this one. Think it's a fairly bad issue, and would rather fix it for 3.5 (and backport to previous LTS)?

I'd go with deferred deletion. I couldn't think of another solution that is watertight.

I'd go with deferred deletion. I couldn't think of another solution that is watertight.
Author
Owner

Committed as d66672e17a.

Committed as d66672e17a.
Blender Bot added the
Status
Archived
label 2023-03-03 15:34:28 +01:00
Author
Owner

This unfortunately needs to be re-opened, when massively generating reports from threaded code it still causes several issues. Will update description for specific info.

This unfortunately needs to be re-opened, when massively generating reports from threaded code it still causes several issues. Will update description for specific info.
Author
Owner

Actually better use a new task imho: #112537

Actually better use a new task imho: #112537
Blender Bot added
Status
Confirmed
and removed
Status
Archived
labels 2023-09-18 18:22:40 +02:00
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-09-18 18:44:31 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105369
No description provided.