Forum moved here!

Home / SessionData gets erased upon exit, so RestoreSession fails

ptr

Hi,

I am using SumatraPDF v3.3.3 64-bit.

I would like SumatraPDF to restore the previous session every time it starts. This never happens, despite my setting RestoreSession = true.

This is likely because when I exit SumatraPDF, the program automatically erases the SessionData section of SumatraPDF-settings.txt.

I came to that conclusion by comparing the SumatraPDF-settings.txt file during a session (just before Exit), to the SumatraPDF-settings.txt just after Exit.

Here is an example. Just before Exit:

# For documentation, see https://www.sumatrapdfreader.org/settings/settings3-3-1.html

MainWindowBackground = #80fff200
EscToExit = false
ReuseInstance = true
UseSysColors = false
RestoreSession = true
TabWidth = 300

FixedPageUI [
	TextColor = #000000
	BackgroundColor = #ffffff
	SelectionColor = #f5fc0c
	WindowMargin = 2 4 2 4
	PageSpacing = 4 4
	HideScrollbars = false
]
EbookUI [
	FontName = Georgia
	FontSize = 12.5
	TextColor = #5f4b32
	BackgroundColor = #fbf0d9
	UseFixedPageUI = false
]
ComicBookUI [
	WindowMargin = 0 0 0 0
	PageSpacing = 4 4
	CbxMangaMode = false
]
ChmUI [
	UseFixedPageUI = false
]
ExternalViewers [
]
ShowMenubar = true
ReloadModifiedDocuments = true
FullPathInTitle = false
ZoomLevels = 8.33 12.5 18 25 33.33 50 66.67 75 100 125 150 200 300 400 600 800 1000 1200 1600 2000 2400 3200 4800 6400
ZoomIncrement = 0

PrinterDefaults [
	PrintScale = shrink
]
ForwardSearch [
	HighlightOffset = 0
	HighlightWidth = 15
	HighlightColor = #6581ff
	HighlightPermanent = false
]
Annotations [
	HighlightColor = #ffff00
]
CustomScreenDPI = 0

RememberStatePerDocument = true
UiLanguage = en
ShowToolbar = true
ShowFavorites = false
AssociateSilently = false
CheckForUpdates = true
RememberOpenedFiles = true
EnableTeXEnhancements = false
DefaultDisplayMode = automatic
DefaultZoom = fit width
WindowState = 2
WindowPos = 724 0 562 728
ShowToc = true
SidebarDx = 150
TocDy = 0
TreeFontSize = 0
ShowStartPage = true
UseTabs = false

FileStates [
	[
		FilePath = G:\AMS eBooks\chel382 Generalized Functions, Volume 6 - Representation Theory and Automorphic Functions.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 -1
		PageNo = 1
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel381 Generalized Functions, Volume 5 - Integral Geometry and Representation Theory.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 71.4693
		PageNo = 293
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel380 Generalized Functions, Volume 4 - Applications of Harmonic Analysis.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 357.345
		PageNo = 35
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel379 Generalized Functions, Volume 3 - Theory of Differential Equations.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 46.7003
		PageNo = 177
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel378 Generalized Functions, Volume 2 - Spaces of Fundamental and Generalized Functions.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 246.4
		PageNo = 177
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel377 Generalized Functions, Volume 1 - Properties and Operations.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 150.42
		PageNo = 30
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
]
SessionData [
	[
		TabStates [
			[
				FilePath = G:\AMS eBooks\chel377 Generalized Functions, Volume 1 - Properties and Operations.pdf
				DisplayMode = continuous
				PageNo = 30
				Zoom = fit width
				Rotation = 0
				ScrollPos = -1 150.42
				ShowToc = true
			]
		]
		TabIndex = 1
		WindowState = 2
		WindowPos = 724 0 562 728
		SidebarDx = 150
	]
	[
		TabStates [
			[
				FilePath = G:\AMS eBooks\chel378 Generalized Functions, Volume 2 - Spaces of Fundamental and Generalized Functions.pdf
				DisplayMode = continuous
				PageNo = 177
				Zoom = fit width
				Rotation = 0
				ScrollPos = -1 246.4
				ShowToc = true
			]
		]
		TabIndex = 1
		WindowState = 2
		WindowPos = 724 0 562 728
		SidebarDx = 150
	]
	[
		TabStates [
			[
				FilePath = G:\AMS eBooks\chel379 Generalized Functions, Volume 3 - Theory of Differential Equations.pdf
				DisplayMode = continuous
				PageNo = 177
				Zoom = fit width
				Rotation = 0
				ScrollPos = -1 46.7003
				ShowToc = true
			]
		]
		TabIndex = 1
		WindowState = 2
		WindowPos = 724 0 562 728
		SidebarDx = 150
	]
	[
		TabStates [
			[
				FilePath = G:\AMS eBooks\chel380 Generalized Functions, Volume 4 - Applications of Harmonic Analysis.pdf
				DisplayMode = continuous
				PageNo = 35
				Zoom = fit width
				Rotation = 0
				ScrollPos = -1 357.345
				ShowToc = true
			]
		]
		TabIndex = 1
		WindowState = 2
		WindowPos = 724 0 562 728
		SidebarDx = 150
	]
	[
		TabStates [
			[
				FilePath = G:\AMS eBooks\chel381 Generalized Functions, Volume 5 - Integral Geometry and Representation Theory.pdf
				DisplayMode = continuous
				PageNo = 293
				Zoom = fit width
				Rotation = 0
				ScrollPos = -1 71.4693
				ShowToc = true
			]
		]
		TabIndex = 1
		WindowState = 2
		WindowPos = 724 0 562 728
		SidebarDx = 150
	]
	[
		TabStates [
			[
				FilePath = G:\AMS eBooks\chel382 Generalized Functions, Volume 6 - Representation Theory and Automorphic Functions.pdf
				DisplayMode = continuous
				PageNo = 1
				Zoom = fit width
				Rotation = 0
				ScrollPos = -1 -1
				ShowToc = true
			]
		]
		TabIndex = 1
		WindowState = 2
		WindowPos = 724 0 562 728
		SidebarDx = 150
	]
]
TimeOfLastUpdateCheck = 30914763 1689483935
OpenCountWeek = 561

# Settings after this line have not been recognized by the current version

Just after Exit:

# For documentation, see https://www.sumatrapdfreader.org/settings/settings3-3-1.html

MainWindowBackground = #80fff200
EscToExit = false
ReuseInstance = true
UseSysColors = false
RestoreSession = true
TabWidth = 300

FixedPageUI [
	TextColor = #000000
	BackgroundColor = #ffffff
	SelectionColor = #f5fc0c
	WindowMargin = 2 4 2 4
	PageSpacing = 4 4
	HideScrollbars = false
]
EbookUI [
	FontName = Georgia
	FontSize = 12.5
	TextColor = #5f4b32
	BackgroundColor = #fbf0d9
	UseFixedPageUI = false
]
ComicBookUI [
	WindowMargin = 0 0 0 0
	PageSpacing = 4 4
	CbxMangaMode = false
]
ChmUI [
	UseFixedPageUI = false
]
ExternalViewers [
]
ShowMenubar = true
ReloadModifiedDocuments = true
FullPathInTitle = false
ZoomLevels = 8.33 12.5 18 25 33.33 50 66.67 75 100 125 150 200 300 400 600 800 1000 1200 1600 2000 2400 3200 4800 6400
ZoomIncrement = 0

PrinterDefaults [
	PrintScale = shrink
]
ForwardSearch [
	HighlightOffset = 0
	HighlightWidth = 15
	HighlightColor = #6581ff
	HighlightPermanent = false
]
Annotations [
	HighlightColor = #ffff00
]
CustomScreenDPI = 0

RememberStatePerDocument = true
UiLanguage = en
ShowToolbar = true
ShowFavorites = false
AssociateSilently = false
CheckForUpdates = true
RememberOpenedFiles = true
EnableTeXEnhancements = false
DefaultDisplayMode = automatic
DefaultZoom = fit width
WindowState = 2
WindowPos = 724 0 562 728
ShowToc = true
SidebarDx = 150
TocDy = 0
TreeFontSize = 0
ShowStartPage = true
UseTabs = false

FileStates [
	[
		FilePath = G:\AMS eBooks\chel382 Generalized Functions, Volume 6 - Representation Theory and Automorphic Functions.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 469.321
		PageNo = 137
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel381 Generalized Functions, Volume 5 - Integral Geometry and Representation Theory.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 71.4693
		PageNo = 293
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel380 Generalized Functions, Volume 4 - Applications of Harmonic Analysis.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 357.345
		PageNo = 35
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel379 Generalized Functions, Volume 3 - Theory of Differential Equations.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 46.7003
		PageNo = 177
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel378 Generalized Functions, Volume 2 - Spaces of Fundamental and Generalized Functions.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 246.4
		PageNo = 177
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
	[
		FilePath = G:\AMS eBooks\chel377 Generalized Functions, Volume 1 - Properties and Operations.pdf
		Favorites [
		]
		IsPinned = false
		IsMissing = false
		OpenCount = 1
		UseDefaultState = false
		DisplayMode = continuous
		ScrollPos = -1 150.42
		PageNo = 30
		Zoom = fit width
		Rotation = 0
		WindowState = 2
		WindowPos = 724 0 562 728
		ShowToc = true
		SidebarDx = 150
		DisplayR2L = false
		ReparseIdx = 0
	]
]
SessionData [
]
TimeOfLastUpdateCheck = 30914763 1689483935
OpenCountWeek = 561

# Settings after this line have not been recognized by the current version

I have tested this with three methods of closing SumatraPDF:
(a) File menu → Exit
(b) End task using Task Manager
(c) Shut down of the PC

In all three cases, SessionData is empty after the exit, even though SessionData had several entries just before the exit.

What should I do to make RestoreSession work?

Many thanks for your advice!

kjk

It should just work and it does work.

My best guess is that some other process deletes SumatraPDF-settings.txt.
Then sumatra re-creates it with default settings, which looks as if SessionData was removed.

You can use a program like process monitor from sysinternals (Process Monitor - Windows Sysinternals | Microsoft Docs) to see which process does access the settings file. It should only be SumatraPDF.exe (and MsMpEng.exe which is Microsoft’s anti-virus software).

(you have to use filter feature to narrow down things to just this file as it shows a lot of data by default)

If you see multiple Sumatra processes then that’s bad. And if you see any process that deletes the file, then that’s the problem.

ptr

Thank you so much, Krzysztof, for your advice! I followed your instructions and used Process Monitor to see what was going on when I was exiting SumatraPDF.

Here is what I found:

(TL;DR version is at the end)

  1. Just before the exit, SumatraPDF had 27 files open in 27 windows (no multiple tabs). The SessionData in SumatraPDF-settings.txt contained a list of all the open windows.

  2. When I exited the program using File menu → Exit, Process Monitor recorded 890 events that accessed SumatraPDF-settings.txt in the space of 2 seconds.

  3. 826 out of the 890 events were by SumatraPDF.exe, all with the same PID (so I know it was a single SumatraPDF process). In addition, there were 54 accesses by MsMpEng.exe, 8 by svchost.exe, and 2 by Explorer.EXE.

  4. The following pattern was repeated 27 times – 10 operations by SumatraPDF.exe (CreateFile, QueryStandardInformationFile, ReadFile, ReadFile, CloseFile, CreateFile, WriteFile, CloseFile, CreateFile, QueryEAFile), followed by 2 operations by MsMpEng.exe (CreateFileMapping, QueryStandardInformationFile), followed by 2 more operations by SumatraPDF.exe (QueryBasicInformationFile, CloseFile).

  5. Note above that there were 27 WriteFile operations by SumatraPDF. These operations progressively reduced the size of SumatraPDF-settings.txt from an initial 113,390 bytes, to a final 102,321 bytes.

  6. The final SumatraPDF-settings.txt file has an empty SessionData section.

  7. But its FileStates section still contains the states of all my 211 previously-opened files. Therefore, this file could not have been re-created by SumatraPDF from default settings after SumatraPDF-settings.txt was deleted by some other process.

TL;DR: The output of Process Monitor suggests that as SumatraPDF was closing my 27 open windows, it made 27 WriteFile operations on SumatraPDF-settings.txt in order to delete the corresponding entries in SessionData.

How do I change this behavior and preserve the SessionData?

Thanks again!

ptr

By the way, I have saved the output of Process Monitor, in PML and CSV formats, and I can send the files to you if you want to see them.

kjk

Thanks for looking into it further.

If you’re not using tabs then this behavior is expected.

I made a decision to only save state of the window if it has more than one file open. The thinking was that otherwise you open on a start page (when using tabs) so the file will be there and easy to open with one click.

I didn’t consider scenario like yours i.e. not using tabs and opening lots of windows.

Please open an issue on github if you want to see that changed.

ptr

Okay, thanks for the explanation!

Yes, I suppose my usage scenario is a bit uncommon. In my work (academic research), I have to open a large number of documents in the process of chasing up references to the literature. I also need to switch frequently between these documents, which is why I need them in separate windows and not in tabs.

(If the documents are in separate windows, I can switch between them by using Alt+Tab, or by clicking the SumatraPDF icon in the Windows Taskbar. But if they are in tabs, it is harder to switch between them, because I don’t know how to see the list of all the open tabs in multiple windows, or to find a recently-looked-at tab using something like Alt+Tab.)

I also need to keep these documents open for long periods of time, or, if I am forced to end the session, to have them reopened at the same position where I left off. That is why RestoreSession is invaluable to me.

For now, I will simulate this functionality by backing up the SessionData before closing my session, and making regular backups to guard against crashes.

I don’t know how GitHub works, so I cannot to ‘open an issue’ there yet, but maybe I will do so in the near future.

Thank you, Krzysztof, for your development work on SumatraPDF! The program is essential to my productivity, for several reasons:

  1. Because it is light on the memory, I can open dozens of documents, and keep them open for long periods of time, without my system becoming unstable. (In contrast to Adobe PDF, which leaks memory, and can fill up most of my RAM if kept open for several days.)

  2. Because it can also read other formats, especially djvu. (Again, in contrast to Adobe PDF.)

  3. Because of its smart Back/Forward feature (Alt+Left Arrow / Alt+Right Arrow), which always goes to the real previous/next view in the document and ignores minor motions of the document. For example, if while reading Chapter 2 of a book I come across a reference to item [147] in the References section, I can jump to the References, scroll around to see what [147] is, and then return to my place in Chapter 2 with a single press of Alt+Left Arrow. But in Adobe PDF or MacOS Preview, I would have to press Alt+Left Arrow numerous times, because they count all the motions of the document made while I was looking for [147] as separate “views”.
    (This may seem like a small thing, but when you are reading non-hyperlinked documents all day, it adds up to a lot of time saved finding your place in the document.)

Being penniless, I have not yet contributed any money to your project, but I hope to do so in the future. :wink:

GitHubRulesOK

The latest pre-release includes “tooltips on hover tabs” so its easier to check which is which if using say two windows rather than 27 :slight_smile: you can also drag tabs into a preferred order to aid finding that key one at left (alt+1) or other alt number 2nd=Alt+2

ptr

Great ideas! I’ll try them, thanks!