poke1024 / tove2d

Animated vector graphics for LÖVE.
Other
171 stars 8 forks source link

Segfault on node amount mismatch when creating flipbook #8

Closed pdesaulniers closed 5 years ago

pdesaulniers commented 5 years ago

If I add a node to gradient-circle_00002.svg in the blob demo, I get a crash in nanosvg. Here is the gdb backtrace:

INSERT (gdb) bt
#0  0x00007fffd3b2f4be in tove::nsvg__flattenShapeStroke (r=0x5555579ee4f0, shape=0x555557921ae8, scale=1) at src/cpp/../thirdparty/nanosvgrast.h:757
#1  0x00007fffd3b3269e in tove::nsvg::shapeStrokeBounds (bounds=0x555557921ad4, shape=0x555557921ae8, scale=1, quality=0x0) at src/cpp/nsvg.cpp:154
#2  0x00007fffd3b3932d in tove::Path::getExactBounds (this=0x555557921a10) at src/cpp/path.cpp:328
#3  0x00007fffd3b199f8 in tove::Graphics::<lambda(const PathRef&)>::operator()(const tove::PathRef &) const (__closure=0x7fffffffdb97, path=std::shared_ptr<tove::Path> (use count 1, weak count 0) = {...}) at src/cpp/graphics.cpp:405
#4  0x00007fffd3b1a346 in tove::Graphics::computeBounds<tove::Graphics::getExactBounds()::<lambda(const PathRef&)> >(float *, const tove::Graphics::<lambda(const PathRef&)> &) (this=0x555557cfad80, bounds=0x555557cfadc4, get=...) at src/cpp/graphics.h:107
#5  0x00007fffd3b19a52 in tove::Graphics::getExactBounds (this=0x555557cfad80) at src/cpp/graphics.cpp:404
#6  0x00007fffd3b045dd in GraphicsGetBounds (shape=..., exact=true) at src/cpp/interface/api.cpp:551
#7  0x00007ffff7a2ba9b in ?? () from /usr/lib/libluajit-5.1.so.2
#8  0x00007ffff7a63510 in ?? () from /usr/lib/libluajit-5.1.so.2
#9  0x00007ffff7a63ddb in ?? () from /usr/lib/libluajit-5.1.so.2
#10 0x00007ffff7a29916 in ?? () from /usr/lib/libluajit-5.1.so.2
#11 0x00007ffff7a6f780 in ?? () from /usr/lib/libluajit-5.1.so.2
#12 0x00007ffff7a29916 in ?? () from /usr/lib/libluajit-5.1.so.2
#13 0x0000555555555295 in ?? ()
#14 0x00007ffff7881223 in __libc_start_main () from /usr/lib/libc.so.6
#15 0x00005555555554ce in ?? ()

Here's the modified svg, with the additional node: gradient-circle_00002.svg.zip

poke1024 commented 5 years ago

I fixed the crash but now nothing gets displayed. I need to investigate what goes wrong here.

poke1024 commented 5 years ago

This is fixed now, and I fixed two related bugs that showed up in this case. TÖVE now also gives various warnings to explain what's happening.

There's no animation happening. Here's why: as you noted, you added a new node in the second SVG. This means there's now a mismatch of number of points. You see this in the SVG file's path definitions:

M 702.000 211.947 C 667.800 93.619 478.779 135.468 387.301 209.291 C 300.271 279.524 204.994 395.709 283.385 475.469 C 362.889 556.362 504.157 487.125 541.982 360.093 C 566.339 278.296 725.443 293.058 702.000 211.947 Z (13 points)

m 613.111,325.608 c -5.80712,-25.87666 7.03067,-54.65462 20.44676,-81.66725 C 651.07068,208.67938 669.56902,176.42611 648.867,157.561 509.083,40.257 281.831,403.2 393.403,547.601 480.611,660.469 919.985,524.845 737.975,457.726 671.222,433.109 632.164,393.364 613.111,325.608 Z (16 points)

TÖVE doesn't know to to interpolate this. The first SVG would need an additional node in order to be able to animate to the second SVG.