Macro ThisComponent.getSheets() invocation fails during autorecovery

Autorecovery problem:

  • After an anomalous crash LO shows dialog that it will save and recover files on next launch.
  • LO shows autorecovery dialog on next launch as expected.
  • User selects option to go ahead and recover files listed.
  • As it loads, a file with macros executes the macros (without normal permission request?) but macros fail when invoking getSheets() method from ThisComponent.

The recovery can become unmanageable (dismissing BASIC error reports), and practically LO must be terminated via Task Manager, which could endanger file recovery.

The full UDF that fails, with a comment where BASIC reports the error:

Function SheetName(Optional sheetIndex As Variant)
	Dim Result As Variant
	Dim Row As Integer
	Dim Column As Integer
	Dim Index as Variant

	If IsMissing(sheetIndex) Then
		SheetName = ThisComponent.CurrentController.Activesheet.Name
		Exit Function
	ElseIf IsEmpty(sheetIndex) Then	
		SheetName = ThisComponent.CurrentController.Activesheet.Name
		Exit Function
	ElseIf IsNull(sheetIndex) Then
		SheetName = ThisComponent.CurrentController.Activesheet.Name
		Exit Function
	End If

	If IsArray(sheetIndex) Then
		ReDim Result(LBound(sheetIndex) to UBound(sheetIndex), LBound(sheetIndex,2) to UBound(sheetIndex,2))
		For Row = LBound(sheetIndex,1) to UBound(sheetIndex,1)
			For Column = Lbound(sheetIndex,2) to UBound(sheetIndex,2)
				REM Specifically, empty entries in sheetIndex() will be "", the empty string
				If IsNumeric(sheetIndex(Row, Column)) Then
					Index = sheetIndex(Row, Column) - 1
					If (Index >= 0) And (Index < ThisComponent.Sheets.Count) Then
						Result(Row, Column) = ThisComponent.Sheets(Index).getName
					Else		 
						Result(Row, Column) = AsErr(502)
					End If
				End If
			Next Column
		Next Row
		SheetName = Result
	Else
		If IsNumeric(sheetIndex) Then
			Index = sheetIndex - 1
			If Index <= ThisComponent.getSheets().Count - 1 Then 'FAILS HERE ONLY ON AUTORECOVERY
				SheetName = ThisComponent.Sheets(Index).getName
			Else
				'NOP
			EndIf
		Else
			SheetName = AsErr(502)
		End If
	End If
	
End Function

I’ll take advice on how this could be narrowed down, as it requires a crash to initiate the chain of events. I seem to recall similar experiences going back to early 7.x.

Version: 24.8.1.2 (X86_64) / LibreOffice Community
Build ID: 87fa9aec1a63e70835390b81c40bb8993f1d4ff6
CPU threads: 20; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Vulkan; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded

Try:

On Error GoTo ErrorHandler

That would probably fix this particular instance. But less “selfishly,” what is different about the autorecovery context, and how could we stop it from happening to others (possibly future me) without the need to wrap every UDF in error handling? With bigger projects I’ll have error stacks and handlers everywhere, and seldom will there be significant data loss from an odd crash. But it is annoying, and most users would feel very trapped, likely unsure of how to use something like Task Manager to kill the LO processes.

File a bug report :slight_smile:

Is there a way to force a crash at the “gracious exit” level where LO shows the closing dialog before exiting so I can pare down the macro and work some details and confirm repeatability before filing a bug?

[The few times this has happened in v. 28 it has been switching from one sheet tab to another: the requested sheet appears, cell selection is indicated by highlighting of the row number and column letter, but the active cell box never appears. Multiple selections are possible with no active cell box showing up…it’s not just “sluggish”. Then switching back to the previous sheet regains the active cell box, but the system seems to quickly destabilize and crash.]

Kill the process at the required point?