TeXworks / texworks

Main codebase for TeXworks, a simple interface for working with TeX documents
https://tug.org/texworks/
GNU General Public License v2.0
674 stars 126 forks source link

Last part of TeX document not displayed in editor when opening #1055

Open charlesnix opened 1 week ago

charlesnix commented 1 week ago

When opening some specific TeX files, which I use as templates, the editor only displays the first 88 lines and nothing below. The file is verified to have no special hidden characters with a hex editor.

Cycling line numbering off and on will clear the problem and display the whole file, however, the problem occurs regardless of whether line numbering is on by default or off by default

If line numbering is on when the file is opened, the line numbers above 88 are displayed all piled on top of each other where 89 should be displayed.

Occasionally, TeXworks has crashed before the whole file is displayed.

I have one file which will reliably do this almost every time. I can submit it for analysis if needed

0.7~202406030453~git~a3f4bed6-1jammy obtained from PPA Ubuntu MATE 22.04 LTS

jlaurens commented 1 week ago

IIRC, I had similar problems due to hidden characters entered accidentally. Can you reproduce the bug with a small document and share it?

charlesnix commented 1 week ago

I will experiment with that over the next few days.

There were no special characters near the lines where it stops displaying. I checked in a hex dump. But I have not tried shortening the file by deleting lines starting at the beginning.

charlesnix commented 1 week ago

I have experimented a bit more with a test file copy of the original. Have tried commenting out sections with unpredictable results--sometimes it loads--sometimes it doesn't. Have also discovered that if I open the file sometimes it displays correctly, and other times it doesn't. This can happen back-to-back with no file changes in between. Just opening and exiting several times in a row, sometimes the full file is displayed, sometimes it is not.

I ran an inverse grep for :print: character class and get no non-printable characters. Have confirmed that with visual examination in hexdump.

Oddly, the same document now, when it fails to display, stops at line number 91 instead of 88. I have verified with diff that there are no differences between my test file and the original document.

So, I can't even reproduce the bug every single time with the original document, let alone a MWE. But most times it loads and displays like this: Screenshot at 2024-06-27 09-35-53

charlesnix commented 1 week ago

One further oddity: if you place the cursor in the correctly displayed section and scroll down, or advance the cursor into the undisplayed section, sometimes the missing parts suddenly display. Sometimes advancing the cursor into the undisplayed section causes the TeXworks window to crash with SIGSEGV with something about a reason "reading NULL VMA"

I sent the crash report in from apport.

Will gladly post the offending document, but have had no luck bisecting to a single portion of the document that causes the issue. With a segmentation fault happening sometimes, I am not clear this really is a document problem.

stloeffler commented 13 hours ago

Unfortunately, it seems that this is QTBUG-20354 yet again (see also #469). This was fixed in some versions of Qt5, but the fix caused other problems, so it was reverted and the problem resurfaced. I am currently looking into possibilities to migrate the editor to QScintilla (which works differently and therefore shouldn't be affected by this issue; plus, this would bring other advanced features like code folding), but that's a huge change so I can't give a timeline for it right now unfortunately.

What might help as a work-around when you notice the problem is to force Qt to reformat the text, e.g., by some combination of toggling line numbers, toggling syntax highlighting, and resizing the window.