Buggy draft target.

Is anyone else having problems with the draft target? My word count jumps erratically as I work-- last night it showed that 23,700 words had been written and this morning it was down to 23,300. Thankfully nothing had been deleted. This makes the session target fluctuate as well. It happens while the document is ope, and quitting Scrivener doesn’t seem to help.

Are you using some form of automatic synchronisation, such as provided by Dropbox? If so, you could be running into some sync conflicts, and that should be attended to as it could lead to more serious problems (though to be clear, in most cases, not fatal as these systems duplicate files they cannot resolve automatically, meaning the stuff is still there, just not visible to Scrivener) than a word count fluctuation.

If you aren’t syncing, then the search index just may be out of whack. Try resetting it by clicking on the File menu, holding down the Option key, and selecting the Save and Rebuild Search Indexes command that will appear. This should fix things immediately, no need to reload.

Thank you so much! I’ll try that and see if it works! :slight_smile:

Unfortunately, this still keeps happening. I’m not syncing, and using Scrivener only on this laptop.

Do you change your compile settings frequently? Most of the stats features in the software treat the current compile group as the thing you’re working on. So if you set that to one chapter out of ten, your word count will “plummet”.

Haven’t touched that at all yet. :confused:

All right, well I’d just keep an eye on it—you can leave that target window open while you type, so it’s no big deal. If you see it suddenly jump, try to think of the last few things you did. If you can find a way to make it jump repeatedly by doing something that otherwise shouldn’t impact it, then let me know.

All righty, thank you! :slight_smile:

I’ve just had exactly the same thing. I have the project targets window open while I’m working, and the manuscript word count just dropped by about 10,000 words while I was away in the loo just now. I hadn’t done anything to it – no changes of settings, nothing. When I looked at the outline, I found that it had set a lot of the word counts for individual scenes to zero, or to much lower numbers than they were before. I’m having to go through opening each one and getting the word count accurate again that way. It’s a real pain though, and the count still hasn’t quite reached what it was before. And I’ve had my sync software (Sugarsync) turned off for the last few days.

It would be great if Scrivener wouldn’t do this. It’s done it before.

Had the project been open for more than three days? Did closing and reopening the project fix it? The only thing I can think of that might cause this is unused text files being cleared from memory (closed) after they haven’t been used for three days. However, looking at the code, I still can’t see why that would cause it, as the word count methods are careful to check for this and recache the count as this happens. So there’s not much I can do without more information at the moment, as these are the only two reports I’ve heard of this happening and I can’t see any obvious culprit in the code (meaning it must be something more obtuse).

The project has been open for more than three days, and I didn’t try closing and reopening it. I just went through opening each of the scenes. In another project recently a whole scene disappeared (though I don’t know when), and I had to paste it back in from a compile I’d done. And I’ve also had scenes’ notes disappear.

If a scene or notes have disappeared, that is almost certainly something going wrong with your sync platform or computer (you mentioned Sugarsync?) - there’s just no way that Scrivener should be able to wipe notes or scenes like that, since the only time it calls any delete code is in reaction to the Trash being emptied. So I would keep an eye on what is happening with your sync software in that regard.

With the other issue, of the word counts disappearing, the fact that the word count updates itself when you click on the documents suggests that the word count is clearing from memory for some reason, although as I say, I’m not sure what’s causing that. I’m guessing the three-day close-unused-stuff code is kicking in, so I’ll take another look at that, but if you can find a reproduction case or think of any other information, that would be very helpful.

Out of curiosity, have you trashed any items that were being counted, during the session? I’ve been working with someone that has made a similar report, and they noted the problem seems to start only after having trashed (not necessarily fully deleted) a chunk of text.

I’ve been having this problem as well. I’ve been discussing it with Support via email, but figured I’d post here as well.

-This is in a project that’s around ~75k.
-It started with minor fluctuations in word count (10-50 words here and there; I was kind of afraid I was going crazy for a while…)
-Then it started jumping several thousand words at a time. I quit and reopened and it stopped for a while. (~4 days?)
-On a suggestion from support, I rebuilt the search index.
-The next day, I moved a single 5k text file from the binder into the trash can. Immediately after doing this, I checked the word count in the project targets window. The word count had dropped from 77k to 972 words (which was the word count of the text file I was in when I checked the project target window.) When I clicked into other chapters and opened up project targets, the word count of that chapter would be added to the total word count (so for instance I would click into a chapter that had 1,000 words, and the new word count would be 1,972 words.) However it wouldn’t update the word count if I only clicked into a chapter without also opening the project targets window.
-Quitting and reopening brought the total back up to where it should be, around 72k. I haven’t written in that project since then.
-I leave my projects open for weeks at a time and I don’t have anything set up to sync.

Okay, I think I’ve found the bug!

I took another look at the code, and this time I noticed an error. To explain, here’s what happens:

  • To get the word count for each document, Scrivener first checks to see if the document is open in memory. (A document is open in memory if you’ve opened it in the editor during the session.) If so, it can just grab the word count directly from the open document, because an open document knows its own word count.
  • If the document is not open in memory, Scrivener just grabs the plain text version of the text that is kept around in memory for search purposes. It works out the word count from that, then caches it into a dictionary, with the word count mapped against the internal ID of the document.
  • The document isn’t open in memory and the word count is already cached, then the cached value is used.

On top of this, whenever the project is saved, Scrivener checks to see if any documents open in memory haven’t actually been used for three days. If it finds any that haven’t then, it closes them to free up memory. This way, in theory, Scrivener can be left open for months even for enormous projects containing thousands of files, and without causing memory issues.

The problem was this: when Scrivener closed a document that hadn’t been opened for a while, when it tried to remove its word count cache from memory, it was using the wrong dictionary key to do so (or rather, it was using the right key but in the wrong format - as a number instead of a textual representation of a number), and this meant that the cache wasn’t being removed at all.

This would have the following effect:

  1. Suppose you have Document A with 100 words in it, and it hasn’t been opened. Scrivener caches that 100 words into memory.

  2. You click on Document A to open it and type another 2,000 words in it, so that it now has 2,100 words in it. Scrivener uses the statistics from the open document when calculating its statistics and targets, so all is good.

  3. You work on other documents and leave Scrivener open for a few days, so that Document A hasn’t been open for three days or more.

  4. You trigger a save event in Scrivener (by typing something, or by emptying the Trash, or whatever). Scrivener sees that Document A hasn’t been used for a while and so removes it from memory. At this point it should also remove the old word count (the 100 words) from the cache.

  5. Because in step (4) Scrivener failed to remove the old word count from the cache, now when Scrivener calculates the targets or word counts, it discovers that Document A isn’t open, but that it has a cached word count of 100 words, so it uses that - d’oh!

I’ve fixed this by:

  1. Fixing the underlying problem in (4), so that the cache does get removed correctly.

  2. Also removing the cache when the document is opened into memory (which should make (1) redundant, but redundancy is a good thing).

From the descriptions, this is almost certainly the problem. So, this will be fixed in Scrivener 2.7. In the meantime, if you run into this issue, please just close the project and reopen it (you don’t need to quit Scrivener, you just need to close and reopen the project), as this will cause all the word counts to be re-cached.

Thanks and all the best,

Thanks, Keith, that’s an amazingly thorough answer. It must have been the three-day thing causing the word count to suddenly go wrong, because my last writing session ended at about 7pm on Friday. I didn’t do anything over the weekend, and only looked at one scene on Monday. The word count suddenly went wrong at about 6pm on Monday, which would make sense because the clocks changed over the weekend. I’m glad it’ll be fixed in 2.7.

Thanks for the advice about the scene and the notes disappearing. The scene itself didn’t disappear – just all the words in it. So maybe it was a syncing problem. Sugarsync is absolutely rubbish, so it wouldn’t surprise me. Those problems both happened during long breaks (a few months) in working on projects, though they would have been open in Scrivener for some of that time. I’m writing full-time at the moment though, so I’ll be more likely to notice problems like that as they happen.

Thanks again,


Sweet, thank you for figuring that out, Keith! Good to know I wasn’t actually going crazy. g

Thanks for looking into this! I’m still running into this problem and I’ve found that it happens when I switch between documents in a single project. For what it’s worth, I keep Scrivener projects open all the time, for months at a time, and closing and opening them does not seem to restore the right word count for me…