Apache OpenOffice (AOO) Bugzilla – Issue 76084
Remove a shape from macro crashes OOo drawing document.
Last modified: 2008-03-13 16:15:29 UTC
I was asked how to remove a shape from a drawing document. The following macro, attempts to remove the selected shape, but it crashes instead. Using a drawing, select a single shape and run this macro. Sub Main Dim oShapeName as String Dim oDoc As Object oDoc = ThisComponent oDocCtrl = oDoc.getCurrentController() ' See what is currently selected. oSelection = oDocCtrl.getSelection() If IsEmpty( oSelection ) Then MsgBox( "Zum Löschen muss eine Grafik makiert sein" ) Exit Sub EndIf If oSelection.getCount() > 1 Then MsgBox( "Bitte nur eine Grafik zum löschen auswählen" ) Exit Sub EndIf oOrigShape = oSelection.getByIndex( 0 ) oShapeName = oOrigShape.getName() 'print oShapeName REM I expected that either of these next two statements REM would remove the shape from the document. oOrigShape.Dispose() REM Crash oOrigShape.getParent().Remove(oOrigShape) REM CRASH End Sub
Reproducible. Reassigned.
calc also
Created attachment 45337 [details] remove the empty sdvobject
as the patch's comment. remove the empty SdrObject from MarkedObjectList.
*** Issue 72461 has been marked as a duplicate of this issue. ***
The patch does fix the crash but if the shape was only recently inserted the office still crashes as there is an undo action that still 'owns' the shape deleted by using the api. So the real fix would be the one in issue 74651 by adding an undo action for shape removal and not deleting the SdrObject. I will still add this patch as it makes the selection a little more fail save. But AW suggested not to add it in SdrMarkView::ModelHasChanged but in SdrMarkList::ImpForceSort(), so each time the current mark list is sorted, invalid SdrObjects will be removed. Since this issue will be fixed by issue 74651 I will set this one to duplicate *** This issue has been marked as a duplicate of 74651 ***
closing