On 04/18/2018 03:14 PM, Pavel Sanda wrote:
> Pavel Sanda wrote:
>> There is something weird going on with our section counters.
>> When lyx crashes and leaves emergency file behind, in the next
>> lyx run I choose for loading original and removing emergency file.
>> The 'original' file is loaded but all counters are wrong, starting
>> higher than they should ('5' in this case).
> I have MWE.
> 1. Save two attached files into single directory and cd there.
> 2. $ touch paper.lyx.emergency
> 3. $ lyx paper.lyx
> 4. Hit 'Load Original'
> 5. Hit 'Keep'
> 6. Document is loaded, section counter does not start at 1.
>
> I have a feeling that I was capable to get similar behaviour even without
> the emergency file, but can't reproduce it.

I believe the attached should fix this.

Riki

>
> Pavel


>From 77713b7bf4836699ad91e6b4e35fb884002bc689 Mon Sep 17 00:00:00 2001
From: Richard Heck <rikih...@lyx.org>
Date: Thu, 19 Apr 2018 22:12:44 -0400
Subject: [PATCH] Reset counters before we re-run updateBuffer when the
 bibfiles change.

Fixes a bug reported by Pavel here:
  https://marc.info/?l=lyx-devel&m=152407889727665&w=2
---
 src/Buffer.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 61f2bfc762..1b9138a1ad 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4798,10 +4798,17 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 		// labels. Nothing else will have changed. So we could create a new 
 		// UpdateType that would signal that fact, if we needed to do so.
 		parit = cbuf.par_iterator_begin();
+		// we will be re-doing the counters and references and such.
+		textclass.counters().reset();
+		clearReferenceCache();
+		updateMacros();
+		setChangesPresent(false);
 		updateBuffer(parit, utype);
 	}
-	else
+	else {
+		// this is also set to true on the other path, by reloadBibInfoCache.
 		d->bibinfo_cache_valid_ = true;
+	}
 	d->cite_labels_valid_ = true;
 	/// FIXME: Perf
 	cbuf.tocBackend().update(true, utype);
-- 
2.14.3

Reply via email to