1 |
From a2cb0319ea36bf068557643e9421a81a2aba1947 Mon Sep 17 00:00:00 2001 |
2 |
From: Michael Stahl <mstahl@redhat.com> |
3 |
Date: Wed, 26 Sep 2012 12:43:29 +0200 |
4 |
Subject: [PATCH 4/4] rhbz#827695: sw: prevent crashes after incomplete print: |
5 |
|
6 |
If the last page is not printed for whatever reason, then |
7 |
SwXTextDocument's destructor will delete a SwViewOptionAdjust_Impl, |
8 |
which accesses the document's ViewShell, which has already been |
9 |
deleted at that point. Add a horrible kludge to not crash for now. |
10 |
|
11 |
Change-Id: I67fe37970d60782030b84f2badddd1e66ef3f9c6 |
12 |
(cherry picked from commit d53e12c7a9c2d0a3b487303673c1fafd09f6593c) |
13 |
Reviewed-on: https://gerrit.libreoffice.org/699 |
14 |
Reviewed-by: Noel Power <noel.power@suse.com> |
15 |
Tested-by: Noel Power <noel.power@suse.com> |
16 |
(cherry picked from commit 47014647eced4864e149b923b7eb024418e71782) |
17 |
--- |
18 |
sw/inc/printdata.hxx | 2 +- |
19 |
sw/inc/unotxdoc.hxx | 5 +++-- |
20 |
sw/source/core/view/printdata.cxx | 5 +++++ |
21 |
sw/source/ui/uno/unotxdoc.cxx | 26 ++++++++++++++++++-------- |
22 |
4 files changed, 27 insertions(+), 11 deletions(-) |
23 |
|
24 |
diff --git a/sw/inc/printdata.hxx b/sw/inc/printdata.hxx |
25 |
index 02d56b8..a64ece9 100644 |
26 |
--- a/sw/inc/printdata.hxx |
27 |
+++ b/sw/inc/printdata.hxx |
28 |
@@ -42,7 +42,6 @@ |
29 |
|
30 |
class SwDoc; |
31 |
class SwDocShell; |
32 |
-class ViewShell; |
33 |
class _SetGetExpFlds; |
34 |
class SwViewOption; |
35 |
class OutputDevice; |
36 |
@@ -278,6 +277,7 @@ public: |
37 |
void ViewOptionAdjustStart( ViewShell &rSh, const SwViewOption &rViewOptions); |
38 |
void ViewOptionAdjust( SwPrintData const* const pPrtOptions ); |
39 |
void ViewOptionAdjustStop(); |
40 |
+ void ViewOptionAdjustCrashPreventionKludge(); |
41 |
|
42 |
bool HasSwPrtOptions() const { return m_pPrtOptions != 0; } |
43 |
SwPrintData const* GetSwPrtOptions() const { return m_pPrtOptions.get(); } |
44 |
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx |
45 |
index 42d646f..a460565 100644 |
46 |
--- a/sw/inc/unotxdoc.hxx |
47 |
+++ b/sw/inc/unotxdoc.hxx |
48 |
@@ -587,7 +587,7 @@ public: |
49 |
-----------------------------------------------------------------------*/ |
50 |
class SwViewOptionAdjust_Impl |
51 |
{ |
52 |
- ViewShell & m_rShell; |
53 |
+ ViewShell * m_pShell; |
54 |
SwViewOption m_aOldViewOptions; |
55 |
|
56 |
public: |
57 |
@@ -595,7 +595,8 @@ public: |
58 |
~SwViewOptionAdjust_Impl(); |
59 |
void AdjustViewOptions( SwPrintData const* const pPrtOptions ); |
60 |
bool checkShell( const ViewShell& rCompare ) const |
61 |
- { return &rCompare == &m_rShell; } |
62 |
+ { return &rCompare == m_pShell; } |
63 |
+ void DontTouchThatViewShellItSmellsFunny() { m_pShell = 0; } |
64 |
}; |
65 |
|
66 |
|
67 |
diff --git a/sw/source/core/view/printdata.cxx b/sw/source/core/view/printdata.cxx |
68 |
index 870ecbe..5c8e0ab 100644 |
69 |
--- a/sw/source/core/view/printdata.cxx |
70 |
+++ b/sw/source/core/view/printdata.cxx |
71 |
@@ -131,6 +131,11 @@ void SwRenderData::ViewOptionAdjustStop() |
72 |
m_pViewOptionAdjust.reset(); |
73 |
} |
74 |
|
75 |
+void SwRenderData::ViewOptionAdjustCrashPreventionKludge() |
76 |
+{ |
77 |
+ m_pViewOptionAdjust->DontTouchThatViewShellItSmellsFunny(); |
78 |
+} |
79 |
+ |
80 |
|
81 |
void SwRenderData::MakeSwPrtOptions( |
82 |
SwDocShell const*const pDocShell, |
83 |
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx |
84 |
index 8711d4e..931d5ec 100644 |
85 |
--- a/sw/source/ui/uno/unotxdoc.cxx |
86 |
+++ b/sw/source/ui/uno/unotxdoc.cxx |
87 |
@@ -404,6 +404,13 @@ SwXTextDocument::~SwXTextDocument() |
88 |
xNumFmtAgg = 0; |
89 |
} |
90 |
delete m_pPrintUIOptions; |
91 |
+ if (m_pRenderData && m_pRenderData->IsViewOptionAdjust()) |
92 |
+ { // rhbz#827695: this can happen if the last page is not printed |
93 |
+ // the ViewShell has been deleted already by SwView::~SwView |
94 |
+ // FIXME: replace this awful implementation of XRenderable with |
95 |
+ // something less insane that has its own view |
96 |
+ m_pRenderData->ViewOptionAdjustCrashPreventionKludge(); |
97 |
+ } |
98 |
delete m_pRenderData; |
99 |
} |
100 |
|
101 |
@@ -3861,14 +3868,17 @@ void SwXDocumentPropertyHelper::onChange() |
102 |
|
103 |
SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl( |
104 |
ViewShell& rSh, const SwViewOption &rViewOptions) |
105 |
- : m_rShell( rSh ) |
106 |
+ : m_pShell(&rSh) |
107 |
, m_aOldViewOptions( rViewOptions ) |
108 |
{ |
109 |
} |
110 |
|
111 |
SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl() |
112 |
{ |
113 |
- m_rShell.ApplyViewOptions( m_aOldViewOptions ); |
114 |
+ if (m_pShell) |
115 |
+ { |
116 |
+ m_pShell->ApplyViewOptions( m_aOldViewOptions ); |
117 |
+ } |
118 |
} |
119 |
|
120 |
void |
121 |
@@ -3876,14 +3886,14 @@ SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions) |
122 |
{ |
123 |
// to avoid unnecessary reformatting the view options related to the content |
124 |
// below should only change if necessary, that is if respective content is present |
125 |
- const bool bContainsHiddenChars = m_rShell.GetDoc()->ContainsHiddenChars(); |
126 |
- const SwFieldType* pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENTXTFLD ); |
127 |
+ const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars(); |
128 |
+ const SwFieldType* pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENTXTFLD ); |
129 |
const bool bContainsHiddenFields = pFldType && pFldType->GetDepends(); |
130 |
- pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENPARAFLD ); |
131 |
+ pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENPARAFLD ); |
132 |
const bool bContainsHiddenParagraphs = pFldType && pFldType->GetDepends(); |
133 |
- pFldType = m_rShell.GetDoc()->GetSysFldType( RES_JUMPEDITFLD ); |
134 |
+ pFldType = m_pShell->GetDoc()->GetSysFldType( RES_JUMPEDITFLD ); |
135 |
const bool bContainsPlaceHolders = pFldType && pFldType->GetDepends(); |
136 |
- const bool bContainsFields = m_rShell.IsAnyFieldInDoc(); |
137 |
+ const bool bContainsFields = m_pShell->IsAnyFieldInDoc(); |
138 |
|
139 |
SwViewOption aRenderViewOptions( m_aOldViewOptions ); |
140 |
|
141 |
@@ -3923,7 +3933,7 @@ SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions) |
142 |
if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary |
143 |
{ |
144 |
aRenderViewOptions.SetPrinting( pPrtOptions != NULL ); |
145 |
- m_rShell.ApplyViewOptions( aRenderViewOptions ); |
146 |
+ m_pShell->ApplyViewOptions( aRenderViewOptions ); |
147 |
} |
148 |
} |
149 |
|
150 |
-- |
151 |
1.7.11.4 |
152 |
|