Cleaned up memory management in windows attrstr.cpp; also got rid of the logHRESULT(HELP) I was using in case DirectWrite doesn't return NULL+S_OK on a nonexistent drawing effect (thankfully it does).
This commit is contained in:
parent
70321353a1
commit
78e0684435
|
@ -240,10 +240,8 @@ static HRESULT addEffectAttributeToRange(struct foreachParams *p, size_t start,
|
||||||
while (start < end) {
|
while (start < end) {
|
||||||
hr = p->layout->GetDrawingEffect(start, &u, &range);
|
hr = p->layout->GetDrawingEffect(start, &u, &range);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
{logHRESULT(L"HELP", hr);
|
|
||||||
// TODO proper cleanup somehow
|
|
||||||
return hr;
|
return hr;
|
||||||
} cea = (combinedEffectsAttr *) u;
|
cea = (combinedEffectsAttr *) u;
|
||||||
if (cea == NULL)
|
if (cea == NULL)
|
||||||
cea = new combinedEffectsAttr(attr);
|
cea = new combinedEffectsAttr(attr);
|
||||||
else
|
else
|
||||||
|
@ -257,10 +255,11 @@ static HRESULT addEffectAttributeToRange(struct foreachParams *p, size_t start,
|
||||||
if ((range.startPosition + range.length) > end)
|
if ((range.startPosition + range.length) > end)
|
||||||
range.length = end - range.startPosition;
|
range.length = end - range.startPosition;
|
||||||
hr = p->layout->SetDrawingEffect(cea, range);
|
hr = p->layout->SetDrawingEffect(cea, range);
|
||||||
|
// SetDrawingEffect will AddRef(), so Release() our copy
|
||||||
|
// (and we're abandoning early if that failed, so this will make sure things are cleaned up in that case)
|
||||||
|
cea->Release();
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
// TODO proper cleanup somehow
|
|
||||||
return hr;
|
return hr;
|
||||||
// TODO figure out what and when needs to be released
|
|
||||||
start += range.length;
|
start += range.length;
|
||||||
}
|
}
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -377,11 +376,13 @@ static HRESULT applyEffectsAttributes(struct foreachParams *p)
|
||||||
|
|
||||||
// go through, replacing every combinedEffectsAttr with the proper drawingEffectsAttr
|
// go through, replacing every combinedEffectsAttr with the proper drawingEffectsAttr
|
||||||
range.startPosition = 0;
|
range.startPosition = 0;
|
||||||
|
// and in case this while loop never runs, make hr valid to start with
|
||||||
|
hr = S_OK;
|
||||||
while (range.startPosition < p->len) {
|
while (range.startPosition < p->len) {
|
||||||
hr = p->layout->GetDrawingEffect(range.startPosition, &u, &range);
|
hr = p->layout->GetDrawingEffect(range.startPosition, &u, &range);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
// TODO proper cleanup somehow
|
// note that we are breaking instead of returning; this allows us to clean up on failure
|
||||||
return hr;
|
break;
|
||||||
cea = (combinedEffectsAttr *) u;
|
cea = (combinedEffectsAttr *) u;
|
||||||
if (cea != NULL) {
|
if (cea != NULL) {
|
||||||
auto diter = effects.find(cea);
|
auto diter = effects.find(cea);
|
||||||
|
@ -392,22 +393,21 @@ static HRESULT applyEffectsAttributes(struct foreachParams *p)
|
||||||
effects.insert({cea, dea});
|
effects.insert({cea, dea});
|
||||||
}
|
}
|
||||||
hr = p->layout->SetDrawingEffect(dea, range);
|
hr = p->layout->SetDrawingEffect(dea, range);
|
||||||
|
// don't release dea; we need the reference that's inside the map
|
||||||
|
// (we don't take extra references on lookup, so this will be fine)
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
// TODO proper cleanup somehow
|
break;
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
range.startPosition += range.length;
|
range.startPosition += range.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// and clean up, finally destroying the combinedEffectAttrs too
|
// and clean up, finally destroying the combinedEffectAttrs too
|
||||||
#if 0
|
// we do this in the case of failure as well, to make sure everything is properly cleaned up
|
||||||
TODO
|
|
||||||
for (auto iter = effects.begin(); iter != effects.end(); iter++) {
|
for (auto iter = effects.begin(); iter != effects.end(); iter++) {
|
||||||
iter->first->Release();
|
iter->first->Release();
|
||||||
iter->second->Release();
|
iter->second->Release();
|
||||||
}
|
}
|
||||||
#endif
|
return hr;
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiprivAttributedStringApplyAttributesToDWriteTextLayout(uiDrawTextLayoutParams *p, IDWriteTextLayout *layout, std::vector<struct drawTextBackgroundParams *> **backgroundParams)
|
void uiprivAttributedStringApplyAttributesToDWriteTextLayout(uiDrawTextLayoutParams *p, IDWriteTextLayout *layout, std::vector<struct drawTextBackgroundParams *> **backgroundParams)
|
||||||
|
|
Loading…
Reference in New Issue