Page MenuHome

Freestyle SVG Export: Exception when render layer does not have a freestyle line set
Closed, ResolvedPublic

Description

System Information
Windows 7 Professional SP1
NVIDIA GTX 960

Blender Version
Broken: (example: 2.78 4bble22

When the freestyle SVG export addon is enabled and there are no freestyle line sets but freestyle is enabled the SVGExporterLinesetPanel will query the active freestyle line style and cause and attribute error.
Should this be wrapped with a Try/Except, hasattr or poll function to prevent blender from attempting to access freestyle line styles when they do not currently exist?
Included below is a stack trace of the error as it occurred on my machine.

CRITICAL | 2016-10-27 15:34:12 | 823 | bv: 2.78 (sub 0) |  Uncaught exception
Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\render_freestyle_svg.py", line 193, in draw
    linestyle = freestyle.linesets.active.linestyle
AttributeError: 'NoneType' object has no attribute 'linestyle'

Exact steps for others to reproduce the error

  1. Load default startup file
  2. Enable the Freestyle SVG Export Add on
  3. Enable Freestyle on the render properties panel
  4. Delete the default lineset from the Freestyle Line sets panel in the Render layers properties tab
  5. The above exception should occur

Event Timeline

Vuk Gardašević (lijenstina) triaged this task as Confirmed, Medium priority.

I can confirm the issue. The UI code doesn't have a check for lineset existence, resulting in firing up errors in the console.
@Folkert de Vries (flokkievids) Would you mind take a look? Thanks.

This issue has been resolved. Thanks for the bug report!

@Tamito Kajiyama (kjym3): The core issue here is that its possible to have 0 linesets whilst Freestyle is enabled. In contrast
a scene always has at least one render layer: it's impossible to remove the final one.

I don't see how having 0 linesets would be useful and would propose to make that impossible. Any thoughts?

If I remember correctly, I didn't even consider the possibility of imposing the constraint that there must be at least one lineset. It is easy to check if there's a lineset, and I was not aware of negative effects due to an empty set of linesets.

Making it impossible to have an empty set of linesets is not a good idea, because the data structure representing the set of linesets is part of a scene render layer. The memory for the set of linesets is hence allocated when a new scene render layer is created, so that the set of linesets needs to be populated by a default lineset, which in turn triggers the allocation of a new line style data block, no matter whether Freestyle is enabled or not. Having ten render layers would then imply ten line style data blocks in a .blend file even when you don't use Freestyle, which is unlikely acceptable from non-Freestyle users' perspective.

As to rBA0796f5a8ed8e, you can simply test if freestyle.linesets.active is None and return from the draw() function if that is the case. You don't need to rely on a try-except clause.