Skip to content

Commit cf32ce9

Browse files
committed
Stop the panels building collections while they draw
get_products() reached the MV_Products collection through get_products_root(), which creates and links it when it is missing. Three panels call that from draw(), so merely opening the MultiView sidebar on a file that had never used the add-on linked an MV_Products collection into the scene and left the file marked as modified. Blender does not refuse the write, it just does it, and the resulting data change schedules another redraw: with the sidebar open the panels drew twice per change instead of once. Building data from a draw callback is not something the API promises to keep working either. get_products() now reads bpy.data directly and returns [] when the root is absent. Creation stays in get_products_root(), which only the import and add-collection operators call. Every caller already handled an empty list, since that is what an existing but empty MV_Products returns.
1 parent cdedde5 commit cf32ce9

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎multiview_product_renderer/__init__.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,23 @@ def ensure_collection(name, parent=None):
313313

314314

315315
def get_products_root():
316+
"""The MV_Products collection, created if it is not there yet.
317+
318+
Only for operators. Panels read the products with get_products(), which
319+
never creates anything: draw() runs on every redraw, so reaching for the
320+
root here linked an MV_Products collection into the scene merely because
321+
someone opened the sidebar, and left their file marked as modified for it.
322+
"""
316323
return ensure_collection(PRODUCT_COLL)
317324

318325

319326
def get_products():
320-
return list(get_products_root().children)
327+
"""Product collections, or [] when the root does not exist yet.
328+
329+
Read-only on purpose -- see get_products_root().
330+
"""
331+
root = bpy.data.collections.get(PRODUCT_COLL)
332+
return list(root.children) if root else []
321333

322334

323335
def bbox_of(objs):
@@ -1826,6 +1838,7 @@ def draw(self, context):
18261838
for pc in prods:
18271839
box.label(text=f"{pc.name} ({len(pc.all_objects)} objs)", icon='OUTLINER_COLLECTION')
18281840

1841+
18291842
class MV_PT_Standardize(Panel):
18301843
bl_label = "Standardize"
18311844
bl_space_type = 'VIEW_3D'

0 commit comments

Comments
 (0)