unaligned tcache chunk detected with SkSVGCanvas

268 views
Skip to first unread message

Данил Буланов

unread,
Mar 16, 2024, 5:14:25 AM3/16/24
to skia-discuss
Hello, I have a following code

auto outputStream = new SkDynamicMemoryWStream();
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(SkRect::MakeWH(200, 200), outputStream, SkSVGCanvas::kConvertTextToPaths_Flag);

auto data = outputStream->detachAsData();
data->unref();

It is executed on each frame in HelloWorld example. But it falls with this error "malloc(): unaligned tcache chunk detected"
I understand that there is no outputStream clean up (but it still should not fall I think)
If I add this line
delete outputStream;
then it falls with this "Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)"

What am I doing wrong here?

Данил Буланов

unread,
Mar 16, 2024, 5:25:10 AM3/16/24
to skia-discuss
Ok, now I think that I just dont know how smart pointer works, this code works, I suppose that smart pointer calls unref in its destructor

auto outputStream = new SkDynamicMemoryWStream();
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(SkRect::MakeWH(200, 200), outputStream, SkSVGCanvas::kConvertTextToPaths_Flag);

// drawing..

delete svgCanvas.release();

auto data = outputStream->detachAsData();

delete outputStream;

So this is correct code for wotking with canvas?

суббота, 16 марта 2024 г. в 12:14:25 UTC+3, Данил Буланов:

Данил Буланов

unread,
Mar 16, 2024, 6:29:36 AM3/16/24
to skia-discuss
I have read the code, and compiled this code in release mode, and I still do not understand why calling data->unref() breaks everything.
auto outputStream = new SkDynamicMemoryWStream();
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(SkRect::MakeWH(200, 200), outputStream, SkSVGCanvas::kConvertTextToPaths_Flag);

// drawing..

delete svgCanvas.release();

auto data = outputStream->detachAsData();

delete outputStream;

data->unref();

As I can see there is a check which looks at current ref count and calls delete only if it is 1, which means if I call unref myself, the subsequent unref by sk_sp's destructor will not call delete second time. What am I missing?
The error is still this "malloc(): unaligned tcache chunk detected"
void unref() const {
    if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
        // restore the 1 for our destructor's assert
        SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed));
        delete (const Derived*)this;
    }
}
суббота, 16 марта 2024 г. в 12:25:10 UTC+3, Данил Буланов:

Brian Salomon

unread,
Mar 16, 2024, 7:09:54 AM3/16/24
to skia-d...@googlegroups.com
The ref count variable is part of the SkData object, a member of its base class, SkRefCnt. So once delete is called the the ref count variable cannot accessed, which unref tries to do. 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/09fc8870-6390-4ea1-8aa3-fc86d605af57n%40googlegroups.com.

Данил Буланов

unread,
Mar 16, 2024, 7:24:32 AM3/16/24
to skia-discuss
Ah, that makes sense, thank you!

суббота, 16 марта 2024 г. в 14:09:54 UTC+3, br...@pentrek.com:
Reply all
Reply to author
Forward
0 new messages