summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_pageview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/cpdfsdk_pageview.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_pageview.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 4780d87780..06761a5806 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -175,17 +175,23 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) {
bool CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) {
if (!pAnnot)
return false;
+
CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
if (!pPage || (pPage->GetContext()->GetDocType() != XFA_DocType::Static &&
pPage->GetContext()->GetDocType() != XFA_DocType::Dynamic)) {
return false;
}
+ CPDFSDK_Annot::ObservedPtr pObserved(pAnnot);
if (GetFocusAnnot() == pAnnot)
- m_pFormFillEnv->KillFocusAnnot(0);
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr();
- if (pAnnotHandler)
- pAnnotHandler->ReleaseAnnot(pAnnot);
+ m_pFormFillEnv->KillFocusAnnot(0); // May invoke JS, invalidating pAnnot.
+
+ if (pObserved) {
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandler =
+ m_pFormFillEnv->GetAnnotHandlerMgr();
+ if (pAnnotHandler)
+ pAnnotHandler->ReleaseAnnot(pObserved.Get());
+ }
auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot);
if (it != m_SDKAnnotArray.end())