Issue 76084 - Remove a shape from macro crashes OOo drawing document.
Summary: Remove a shape from macro crashes OOo drawing document.
Status: CLOSED DUPLICATE of issue 74651
Alias: None
Product: Draw
Classification: Application
Component: code (show other issues)
Version: OOo 2.2
Hardware: All All
: P2 Trivial (vote)
Target Milestone: OOo 2.3
Assignee: clippka
QA Contact: issues@graphics
URL:
Keywords:
: 72461 (view as issue list)
Depends on:
Blocks:
 
Reported: 2007-04-04 14:43 UTC by andrew
Modified: 2008-03-13 16:15 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
remove the empty sdvobject (814 bytes, patch)
2007-05-23 10:34 UTC, jianhuajiao
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description andrew 2007-04-04 14:43:57 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
Comment 1 wolframgarten 2007-04-04 15:24:40 UTC
Reproducible. Reassigned.
Comment 2 jianhuajiao 2007-04-20 09:51:35 UTC
calc also
Comment 3 jianhuajiao 2007-05-23 10:34:39 UTC
Created attachment 45337 [details]
remove the empty sdvobject
Comment 4 jianhuajiao 2007-05-23 10:36:03 UTC
as the patch's comment. remove the empty SdrObject from MarkedObjectList.
Comment 5 clippka 2007-07-04 12:29:32 UTC
*** Issue 72461 has been marked as a duplicate of this issue. ***
Comment 6 clippka 2007-07-04 14:15:07 UTC
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 ***
Comment 7 clippka 2007-07-04 14:15:42 UTC
closing
Comment 8 clippka 2008-03-13 16:15:29 UTC
closing