1
$\begingroup$

The code responsible for the error:

def cleanup():
    for s in bpy.data.screens:
        if '.' in s.name or s.name.startswith('temp'): s.user_clear()

    bpy.ops.outliner.orphans_purge(do_recursive=True)

I'm trying to write code that clears a bunch of extra screens that get automatically created every time I use bpy.ops.wm.window_new(). I thought I could just run user_clear() on each screen and then the orphans purge call would automatically remove them. This does work successfully the way I intended it to, however in the system console an error is raised that reads:

ERROR (bke.lib_id): C:\Users\blender\git\blender-v310\blender.git\source\blender\blenkernel\intern\lib_id.c:339 id_us_min: ID user decrement error: SRtemp (from '[Main]'): 0 <= 0

This error doesn't seem to affect the actual functioning of Blender in any way, the rest of the code I've written seems to work as intended, and Blender doesn't crash or exhibit any other strange behaviour. If the system console didn't raise this error, I wouldn't even know anything's amiss. I can't figure out any other way to delete these screens that works as intended, so I'm considering just entirely ignoring this error and moving on, but I know that's not best practice. Why is this error being raised and how can I change my code to avoid this?

$\endgroup$
4
  • $\begingroup$ At first glance I'd say you're trying to clear users of an object that has no users. You may want to test if s.users: docs.blender.org/api/current/… $\endgroup$
    – Gorgious
    Apr 10, 2022 at 16:10
  • $\begingroup$ @Gorgious I've tried putting in print() statements at various points in the code to check exactly which line is causing this error to be raised, and the error is always raised at the orphans_purge line. When I don't run user_clear() on the screens, no error is raised but the screens aren't deleted, and when I run user_clear() on the screens but don't purge the orphans, no error is raised but the screens aren't deleted (until after I close blender and reopen it, but I don't want to have to do that in order to get the screens to delete) $\endgroup$
    – Fez_Master
    Apr 10, 2022 at 16:40
  • $\begingroup$ Can you paste the entire error trace back? $\endgroup$
    – MrBill
    Apr 10, 2022 at 18:59
  • $\begingroup$ @MrBill that is the entire error, there is no traceback. The only text that appears in the console is the text I pasted above, and then on a new line, Info: Deleted 23 data block(s) which happens automatically due to the purge command $\endgroup$
    – Fez_Master
    Apr 10, 2022 at 19:20

1 Answer 1

1
$\begingroup$

This answer was suggested by @Gorgious though their comment seems to have been deleted now.

Instead of running s.user_clear() on each screen, putting all the screens I want to remove in a set and running bpy.data.batch_remove() on that set seems to have accomplished the same intended result with no error being raised. I've got my answer. Don't clear the user, do a batch remove.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .