Skip to content

Commit 7986cb1

Browse files
committed
tools: fix bug where SVG paths with only move commands cause crash
A path like "M5.8,9.1" resulted in a PDC with no points which causes an assert at runtime. Filtering these out at build time avoids this. Signed-off-by: Liam McLoughlin <[email protected]>
1 parent 82b9a3c commit 7986cb1

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

tools/generate_pdcs/pebble_commands.py

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def __init__(self, points, path_open, translate, stroke_width=0, stroke_color=0,
184184
self.type = DRAW_COMMAND_TYPE_PATH if not precise else DRAW_COMMAND_TYPE_PRECISE_PATH
185185
Command.__init__(self, points, translate, stroke_width, stroke_color, fill_color, verbose,
186186
precise, raise_error)
187+
assert(len(points) >= 1)
187188

188189
def serialize(self):
189190
s = pack('B', self.type) # command type

tools/generate_pdcs/svg2commands.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def parse_path(element, translate, stroke_width, stroke_color, fill_color, verbo
9696
if d is not None:
9797
path = svg.path.parse_path(d)
9898
points = [(lambda l: (l.real, l.imag))(line.start) for line in path]
99-
if not points:
99+
move_commands_only = len([line for line in path if isinstance(line, svg.path.Move)]) == len(path)
100+
if not points or move_commands_only:
100101
print("No points in parsed path")
101102
return None
102103

0 commit comments

Comments
 (0)