If macro is running when file is closed libre crashes

At the event ‘open document’ I run a macro that loops in 5 second intervals for 3 minutes searching for files in a directory.

If I wait until the loop is finished then the document closes normally.

If I close the document before that 3 minutes is up Libre crashes with nothing other than a notice it crashed.

The crash report says a generic “Do to an error, LibreOffice has crashed” and where usually the crash report would say the name of the file that crashed there is nothing. The temporary file with the prefix “~” does not get removed.

This is an older version of LibreOffice, 7.042 on Windows 11.

Any ideas on how to interrupt that looping macro or handle the error before it crashes?

I open testCrash.odt, close it immediately, and it doesn’t crash, no matter how long I wait - using either 7.0.0.3 or 25.2.1.2. What should specifically be done to see the crash?

“set a global variable, to break the condition of your looping Sub”

I don’t know what such a global variable would look like or where it would be placed in the module or script. I’d be happy to read any references you can provide.

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: bffef4ea93e59bebbeaf7f431bb02b1a39ee8a59
CPU threads: 8; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded

The code has to fire around when the document or view is or is going to be closed.

Tools/Customize/Events
Document is going to be closed/testCrash.odt

Also crashed when using “View is going to be closed” or other variations on that.

I tested this in my recently updated version of LibreOffice

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: bffef4ea93e59bebbeaf7f431bb02b1a39ee8a59
CPU threads: 8; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded

image

testLooping.odt (9.3 KB)

since it’s not so clear how to reproduce,
maybe also try in Safe Mode

OnViewClosed should do the trick.
see Document Event-Driven Macros

1 Like

Neither OnViewClosed or ViewClosed worked, but it was definitely worth a shot.

Problem posting

which means ? :thinking:

Below is the part that’s forcing the crash. If this Wait command is running when the file is closed there is a crash. I did some testing to find this is the one piece that crashes LibreWriter. I noticed that if Wait is set for 30 seconds and I close my document at 10 seconds everything seems to close good but then 20 seconds later the crash report shows up. The Wait command seems to continue in the background even though the document is closed.


Sub TestCrash
Wait 30000
End Sub

doesn’t anwer the question about OnViewClosed :neutral_face:

It should just set a global variable, to break the condition of your looping Sub, which would then exit normally.

more likely random and OS dependant.

Ask/Guide - How to use the Ask site - The Document Foundation Wiki #More_details

(post deleted by author)