Maniphest T76544

Sculpt mode drawing leaks memory
Closed, ResolvedBUG

Assigned To
Brecht Van Lommel (brecht)
Authored By
Campbell Barton (campbellbarton)
May 8 2020, 1:12 PM
Tags
  • BF Blender
  • Sculpt, Paint & Texture
Subscribers
Ankit Meel (ankitm)
Bohdan Lvov (ostapblender)
Brecht Van Lommel (brecht)
Campbell Barton (campbellbarton)
Jacques Lucke (JacquesLucke)
Pablo Dobarro (pablodp606)
Sergey Sharybin (sergey)
GPU / Viewport

Description

  • Run Blender with -d debug flag.
  • Open this file , exit Blender
  • Error: Not freed memory blocks: 26, total unfreed memory 0.002777 MB
  • Loading the file multiple times increase the number of leaks on exit.

Related Objects

Mentioned In
rB20b94257dc31: Fix part of T76544: dyntopo sculpt undo stack memory leak
T76858: Threading issue in sculpt mode
Mentioned Here
T76858: Threading issue in sculpt mode
rB20b94257dc31: Fix part of T76544: dyntopo sculpt undo stack memory leak
P1394 Disable PBVH Threading
rB18f833be2986: Additional fix for T76426: Mantaflow Liquid - Gravity not respecting Time Scale…
P1376 (An Untitled Masterwork)

Event Timeline

Campbell Barton (campbellbarton) created this task.May 8 2020, 1:12 PM
Campbell Barton (campbellbarton) renamed this task from Sculpt mode leaks memory to Sculpt mode drawing leaks memory.May 8 2020, 1:15 PM
Sergey Sharybin (sergey) added a subscriber: Sergey Sharybin (sergey).May 8 2020, 3:20 PM

Cant reproduce the leak, but do have some heap use after free: P1376
The leak might be different indication of the same root issue.

This is using blender rB18f833be298 on Linux.

Bohdan Lvov (ostapblender) added a subscriber: Bohdan Lvov (ostapblender).May 8 2020, 4:37 PM

I have similar behavior on Windows 10, but only when addons are enabled:

If addons folder are renamed to something different, no errors appear.

Ankit Meel (ankitm) added a subscriber: Ankit Meel (ankitm).May 8 2020, 5:40 PM

File shouldn't be required.. In sculpting workspace, enable Dyntopo, make a stroke, close file.

Brecht Van Lommel (brecht) changed the task status from Needs Triage to Confirmed.May 9 2020, 10:58 AM
Brecht Van Lommel (brecht) changed the subtype of this task from "Report" to "Bug".
Brecht Van Lommel (brecht) added a project: Sculpt, Paint & Texture.
Brecht Van Lommel (brecht) added a subscriber: Pablo Dobarro (pablodp606).
Jacques Lucke (JacquesLucke) added a subscriber: Jacques Lucke (JacquesLucke).May 14 2020, 5:37 PM

I tried to debug this for quite some time today, but I could not track down the root issue yet... I made some observations along the way though.
It's almost certainly a threading issue. I got many different outputs from asan. Furthermore, it's probably not only one issue, but multiple.

Reproduction steps:

  1. Open file.
  2. Start making brush strokes. Usually, it only takes one or two brush strokes to crash when ASAN is enabled.

SCULPT_pbvh_calc_area_normal causes a warning: member call on address 0x613000adefc0 which does not point to an object of type 'task'. It does not seem to have a big impact, but it still feels like there is something wrong with the way parallel_reduce is used in BKE_pbvh_parallel_range.

Applying P1394 seems to fix all the issues for me. It disables threading in various locations. The patch also disables an unrelated assert, that should not be harmful. Enabling threading only on a single one of those, causes crashes. Depending on which one you enable, the crash looks is different. When more are enabled, it seems to be mostly a matter of luck which function fails first.

I tried to find some shared data that is not properly locked, but could not find any yet. I managed to get it working when I locked smaller code segments in the callbacks, but did not really win any significant insights from that.

Brecht Van Lommel (brecht) added a subscriber: Brecht Van Lommel (brecht).May 15 2020, 12:28 AM

This sounds like multiple bugs in a single report? There's many different steps to redo and symptoms here.

The first issue is, does any of this happen in Blender in 2.83? If so, this should probably be a high priority bug. If not, it may be TBB related.

Further, git bisect might help pin down the cause?

Jacques Lucke (JacquesLucke) mentioned this in T76858: Threading issue in sculpt mode.May 18 2020, 3:31 PM
Brecht Van Lommel (brecht) mentioned this in rB20b94257dc31: Fix part of T76544: dyntopo sculpt undo stack memory leak.May 18 2020, 5:29 PM
Brecht Van Lommel (brecht) closed this task as Resolved.May 18 2020, 5:47 PM
Brecht Van Lommel (brecht) claimed this task.

Regarding the various issues reported here:

  • Dyntopo memory leak reported by @Ankit Meel (ankitm): fixed with rB20b94257dc31.
  • Original memory leak in description: unable to reproduce. Assuming this has already been fixed. If it still happens, @Campbell Barton (campbellbarton) should run Blender with --debug-memory and specify the revision tested.
  • GPU draw buffers user after free. Given the asan logs, assuming the issue found by @Sergey Sharybin (sergey) and @Jacques Lucke (JacquesLucke) is the same, and to be handled in T76858: Threading issue in sculpt mode.
  • Memory leak reported by @Bohdan Lvov (ostapblender): this would be a bug in an add-on using the bgl module. If that's an add-on shipped with Blender, a bug can be reported for that add-on.