mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 14:13:43 +00:00
canvas/paint: ++exception handling
enhanced reference count verification to prevent unintentional deletion of used composition targets.
This commit is contained in:
parent
8200bc5fc3
commit
6e3674b904
2 changed files with 7 additions and 3 deletions
|
@ -73,7 +73,7 @@ namespace tvg
|
||||||
~Impl()
|
~Impl()
|
||||||
{
|
{
|
||||||
if (compData) {
|
if (compData) {
|
||||||
delete(compData->target);
|
if (P(compData->target)->unref() == 0) delete(compData->target);
|
||||||
free(compData);
|
free(compData);
|
||||||
}
|
}
|
||||||
delete(smethod);
|
delete(smethod);
|
||||||
|
@ -141,7 +141,10 @@ namespace tvg
|
||||||
if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
|
if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
|
||||||
|
|
||||||
if (compData) {
|
if (compData) {
|
||||||
delete(compData->target);
|
P(compData->target)->unref();
|
||||||
|
if ((compData->target != target) && P(compData->target)->refCnt == 0) {
|
||||||
|
delete(compData->target);
|
||||||
|
}
|
||||||
//Reset scenario
|
//Reset scenario
|
||||||
if (!target && method == CompositeMethod::None) {
|
if (!target && method == CompositeMethod::None) {
|
||||||
free(compData);
|
free(compData);
|
||||||
|
@ -152,6 +155,7 @@ namespace tvg
|
||||||
if (!target && method == CompositeMethod::None) return true;
|
if (!target && method == CompositeMethod::None) return true;
|
||||||
compData = static_cast<Composite*>(calloc(1, sizeof(Composite)));
|
compData = static_cast<Composite*>(calloc(1, sizeof(Composite)));
|
||||||
}
|
}
|
||||||
|
P(target)->ref();
|
||||||
compData->target = target;
|
compData->target = target;
|
||||||
compData->source = source;
|
compData->source = source;
|
||||||
compData->method = method;
|
compData->method = method;
|
||||||
|
|
|
@ -62,7 +62,7 @@ Result Shape::reset() noexcept
|
||||||
pImpl->rs.path.cmds.clear();
|
pImpl->rs.path.cmds.clear();
|
||||||
pImpl->rs.path.pts.clear();
|
pImpl->rs.path.pts.clear();
|
||||||
|
|
||||||
pImpl->flag = RenderUpdateFlag::Path;
|
pImpl->flag |= RenderUpdateFlag::Path;
|
||||||
|
|
||||||
return Result::Success;
|
return Result::Success;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue