# [texworks] Problem with line mangling

Stefan Löffler st.loeffler at gmail.com
Thu Jul 7 10:12:13 CEST 2011

Hi,

On 2011-07-07 08:30, Paul A Norman wrote:
>> in particular for
>> long (1000+ lines) documents
> I had it happening to me while recently testing for it, in a second
> re-opened document (a letter) where \end{document} is at only line 192

Are you talking about 0.4.3 (or a later version), or about the recent
attempt in r862, or something else?
TL'11 contains AFAIK 0.4.4, in which this should be partly resolved. At
least the latest reports (yours and Alain's) I got all included line
numbers close to or about 1000. If there were other cases in recent
versions of Tw that weren't reported (or that I forgot) of course it's
not problem to remove the "long (1000+ lines)" part... it would be a bit
disturbing for me, though, as it doesn't fit my current hypothesis ;).

> I'll look at cleaning up and posting my (auto)back-up scripts, can be
> run manually or on hooks, and allows for remembered' custom
> directories for backup location.

for the software to say 'hey, we ship with a backup script, because we
know our program crashes or causes problems' ;).

> I am also wondering if this could have happened to me in the past when
> line numbers were turned off, as I have found areas later on a reopen,
> where I have re-typed almost identical text on a previous edit, in the
> same general location areas as the original text, which I might have
> previously been putting down to bad work habits due to late night
> work—now I am not so sure it was the late nights.

I can't say, of course. My current hypothesis is that the problem
appears when Qt is trying to put text into a window that has not been
shown. Maybe it is even some kind of race condition that occurs only
when the window is shown while the text is not yet fully ready. But I
haven't been able to make heads or tails of the Qt internals yet.
Anyway, this is consistent with my tests (opening a file from the file
manager vs. opening it into an empty, unmodified document (in which case
the empty window is reused and thus shown already)). Plus, the race
condition would explain why this is fickle (different computer work
loads cause different processing times), and why it happens
predominantly in long documents (if that's the case).

>> TeXworks crashes
> I haven't had an actual crash from this for a long time (months).

It seems to crash only if you move the cursor into and out of such a
hidden line with the arrow keys. From the looks of the debugging
backtrace I did a while ago, some pointers of the line are not
initialized correctly (they are NULL), and those are probably accessed
without proper safe-guarding, resulting in the crash. But as long as you
don't touch those lines, no crash happens.

HTH
Stefan
`