Thank you! Okay, thanks to the project you provided, I have managed to reproduce the crash. (Funnily enough, I could only reproduce it by reverting the code to the old text cursor temporarily, but that allowed me to reproduce a crash upon loading the entire text, producing exactly the same crash log as the ones you posted yesterday.)
It seems to be down to a big change in the way views draw in Sonoma - I had suspected this might be a factor.
Prior to Sonoma, a view could only draw inside its own bounds. As of Sonoma, however, views can draw outside of themselves, and when the system asks a view to redraw, it may pass that view a much larger rectangle to draw than it needs - a rectangle outside of itself. (This was the cause of a bug that made it into 3.3.2, where if you turned the ruler on in dark mode, the text in the editor would disappear - because the ruler was drawing outside itself and filling in the editor area with its background colour.)
So, what seems to be happening is this:
- You load some text in the page view, which then lays out. As it lays out, it creates more pages as needed to contain all of the text.
- During layout, some of the text views (each page contains its own text view) may be told to redraw. Drawing may trigger re-layout, but as long as it’s contained to the bounds of the text view, it won’t hurt, because that area has already been laid out properly since it’s already inside a page that has been created.
- However, on Sonoma, those text views may be told to redraw an area outside of their bounds. This will then trigger layout in text outside of the page.
- This can result in text that is still in the process of being laid out being sent another layout message, and the page view trying to add a page while it’s already in the process of building its pages.
- Crash.
(To clarify, this behaviour only occurs if an app is built on Sonoma and running on Sonoma.)
I have thus updated the code to tell text views inside pages not to allow drawing outside their bounds, which returns them to pre-Sonoma behaviour. Here is a new build with this change (build 16205):
This keeps the previous fix that was mostly working for you too, as I think these may be different bugs. The previous crash was triggered by scaling; I think this crash could occur on long texts even at 100%, given the cause.
Right, I really am going to go and have a weekend now.
All the best,
Keith
P.S. And yes, I’ll delete your project once we’re done reproducing the crashes - fingers crossed this does it…