[Impeller] removed global mutable variable for tessellation allocation function pointers (flutter/engine#46127)

issue: https://github.com/flutter/flutter/issues/125749

This removes a global mutable variable, instead giving each tesellator its own struct.  I suspect the root cause of the linked  issue is memory corruption but this is good cleanup anyways.  If for some reason libTess2 is mutating that global variable at cleanup, that could be the source of this problem and this would fix the issue.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke
2023-09-20 17:22:05 -07:00
committed by GitHub
parent 9b906fb887
commit 6d15ab00ed

View File

@@ -21,7 +21,7 @@ static void HeapFree(void* userData, void* ptr) {
}
// Note: these units are "number of entities" for bucket size and not in KB.
static TESSalloc alloc = {
static const TESSalloc kAlloc = {
HeapAlloc, HeapRealloc, HeapFree, 0, /* =userData */
16, /* =meshEdgeBucketSize */
16, /* =meshVertexBucketSize */
@@ -31,8 +31,14 @@ static TESSalloc alloc = {
0 /* =extraVertices */
};
Tessellator::Tessellator()
: c_tessellator_(::tessNewTess(&alloc), &DestroyTessellator) {}
Tessellator::Tessellator() : c_tessellator_(nullptr, &DestroyTessellator) {
TESSalloc alloc = kAlloc;
{
// libTess2 copies the TESSalloc despite the non-const argument.
CTessellator tessellator(::tessNewTess(&alloc), &DestroyTessellator);
c_tessellator_ = std::move(tessellator);
}
}
Tessellator::~Tessellator() = default;