From 59790ab3d766f34e3252df9cf0b31b897e42e34d Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Thu, 19 Oct 2023 08:21:25 +0200 Subject: [PATCH 1/5] fix TestFileProvider::NextFile() to return temporary string --- src/StressTesting.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/StressTesting.cpp b/src/StressTesting.cpp index 366e205d68dd..619026419daf 100644 --- a/src/StressTesting.cpp +++ b/src/StressTesting.cpp @@ -308,7 +308,7 @@ class TestFileProvider { virtual ~TestFileProvider() { } // returns path of the next file to test or nullptr if done (caller needs to free() the result) - virtual char* NextFile() = 0; + virtual TempStr NextFile() = 0; // start the iteration from the beginning virtual void Restart() = 0; virtual int GetFilesCount() = 0; @@ -339,11 +339,12 @@ class FilesProvider : public TestFileProvider { ~FilesProvider() override { } - char* NextFile() override { + TempStr NextFile() override { if (provided >= files.size()) { return nullptr; } - return str::Dup(files.at(provided++)); + TempStr res = files.at(provided++); + return res; } void Restart() override { @@ -364,7 +365,7 @@ class DirFileProvider : public TestFileProvider { public: DirFileProvider(const char* path, const char* filter); ~DirFileProvider() override; - char* NextFile() override; + TempStr NextFile() override; void Restart() override; int GetFilesCount() override; }; @@ -386,13 +387,13 @@ bool DirFileProvider::OpenDir(const char* dirPath) { bool hasFiles = CollectStressTestSupportedFilesFromDirectory(dirPath, fileFilter, filesToOpen); filesToOpen.SortNatural(); - AutoFreeStr pattern(str::Format("%s\\*", dirPath)); + TempStr pattern = str::FormatTemp("%s\\*", dirPath); bool hasSubDirs = CollectPathsFromDirectory(pattern, dirsToVisit, true); return hasFiles || hasSubDirs; } -char* DirFileProvider::NextFile() { +TempStr DirFileProvider::NextFile() { if (filesToOpen.size() > 0) { return filesToOpen.PopAt(0); } @@ -695,7 +696,7 @@ static void RandomizeViewingState(StressTest* st) { static bool GoToNextFile(StressTest* st) { for (;;) { - AutoFreeStr nextFile(st->fileProvider->NextFile()); + TempStr nextFile = st->fileProvider->NextFile(); if (nextFile) { if (!IsInRange(st->fileRanges, ++st->fileIndex)) { continue; From 00bafba8fe0d56a9db8a7313951070fde6b7f11d Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Thu, 19 Oct 2023 20:58:21 +0200 Subject: [PATCH 2/5] add GetGdiObjectsCount() and CheckGdiLeaks --- src/utils/WinUtil.cpp | 5 +++++ src/utils/WinUtil.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/utils/WinUtil.cpp b/src/utils/WinUtil.cpp index d8f8f440dc3b..691cf0f6c6b8 100755 --- a/src/utils/WinUtil.cpp +++ b/src/utils/WinUtil.cpp @@ -2910,3 +2910,8 @@ void AddPathToRecentDocs(const char* path) { WCHAR* pathW = ToWstrTemp(path); SHAddToRecentDocs(SHARD_PATH, pathW); } + +int GetGdiObjectsCount() { + DWORD n = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS); + return (int)n; +} \ No newline at end of file diff --git a/src/utils/WinUtil.h b/src/utils/WinUtil.h index b20c1de16925..50d0fa608176 100644 --- a/src/utils/WinUtil.h +++ b/src/utils/WinUtil.h @@ -338,3 +338,13 @@ void TbGetRect(HWND hwnd, int buttonId, RECT* rc); void TreeViewExpandRecursively(HWND hTree, HTREEITEM hItem, uint flag, bool subtree); void AddPathToRecentDocs(const char*); + +int GetGdiObjectsCount(); + +struct CheckGdiLeaks { + int initialCount = GetGdiObjectsCount(); + ~CheckGdiLeaks() { + int currCount = GetGdiObjectsCount(); + CrashIf(currCount > initialCount); + } +}; From d30557246f51dd97cf4583da2d6f1699537a34cc Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Thu, 19 Oct 2023 21:27:37 +0200 Subject: [PATCH 3/5] don't over-release critical section --- src/EngineMupdf.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/EngineMupdf.cpp b/src/EngineMupdf.cpp index d2176c00272e..7a7d5c3c91a8 100644 --- a/src/EngineMupdf.cpp +++ b/src/EngineMupdf.cpp @@ -1505,9 +1505,6 @@ EngineMupdf::EngineMupdf() { EngineMupdf::~EngineMupdf() { EnterCriticalSection(&pagesAccess); - // TODO: remove this lock and see what happens - EnterCriticalSection(ctxAccess); - for (FzPageInfo* pi : pages) { DeleteVecMembers(pi->links); DeleteVecMembers(pi->autoLinks); @@ -1541,7 +1538,6 @@ EngineMupdf::~EngineMupdf() { DeleteVecMembers(pages); for (size_t i = 0; i < dimof(mutexes); i++) { - LeaveCriticalSection(&mutexes[i]); DeleteCriticalSection(&mutexes[i]); } LeaveCriticalSection(&pagesAccess); From 9d34538cc4f38332ff67fbe3e74e7be2b358d0c4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Thu, 19 Oct 2023 22:24:13 +0200 Subject: [PATCH 4/5] update translations --- translations/translations.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/translations/translations.txt b/translations/translations.txt index 0cffc7bf17bd..7aaa05461e45 100755 --- a/translations/translations.txt +++ b/translations/translations.txt @@ -1,5 +1,5 @@ AppTranslator: SumatraPDF -79bc16efa4d3423f883b991ead7ed7b5e5c5cb1b +30e97d6fd71649751fcbdfff5968eeb9971e7e60 :%s annotation. Ctrl+click to edit. am:%s մեկնաբանություն: Ctrl+քլիք՝ խմբագրելու համար: az:Qeyd %s. Düzəliş etmək üçün Ctrl+düyməyə basın. @@ -1438,6 +1438,7 @@ uk:Виділити vn:&Nổi Bật :&Keyboard Shortcuts br:Atalhos do Teclado +de:Tasten&kombinationen fr:&Raccourcis clavier it:&Tasti rapidi pl:Skróty &klawiaturowe @@ -5842,6 +5843,7 @@ vn:Đã dọn lịch sử của %d tập tin, đã xóa hình thu nhỏ. am:Պատմության մաքրում... az:Tarixçə silinir... br:Limpando o histórico... +by:Ачыстка гісторыі… ca:S'està esborrant l'historial... cn:正在清除历史记录… cy:Yn clirio hanes... @@ -14204,6 +14206,7 @@ vn:Mở PDF Đã Nhúng am:Բացել նոր պատուհանում az:Yeni pəncərədə aç br:Abrir em Nova Janela +by:Адкрыць у новым акне ca:Obre en una finestra nova cn:在新窗口中打开 cy:Agor Mewn Ffenestr Newydd From 6fac9e910429cb5f1a2fb9f1f93d0ddf98fa0cb2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Thu, 19 Oct 2023 22:47:40 +0200 Subject: [PATCH 5/5] add more logging --- src/ExternalViewers.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ExternalViewers.cpp b/src/ExternalViewers.cpp index cb24f6daa866..28dee94471e1 100644 --- a/src/ExternalViewers.cpp +++ b/src/ExternalViewers.cpp @@ -19,6 +19,8 @@ #include "ExternalViewers.h" #include "Commands.h" +#include "utils/Log.h" + struct ExternalViewerInfo { const char* name; // shown to the user int cmd; @@ -300,6 +302,7 @@ bool CanViewWithKnownExternalViewer(WindowTab* tab, int cmd) { } ExternalViewerInfo* ev = FindExternalViewerInfoByCmd(cmd); if (!ev || ev->exeFullPath == nullptr) { + logfa("CanViewWithKnownExternalViewer cmd: %d, !ev || ev->exeFullPath == nullptr\n", cmd); return false; } // must match file extension @@ -309,6 +312,7 @@ bool CanViewWithKnownExternalViewer(WindowTab* tab, int cmd) { char* ext = path::GetExtTemp(filePath); const char* pos = str::FindI(ev->exts, ext); if (!pos) { + logfa("CanViewWithKnownExternalViewer cmd: %d, !pos\n", cmd); return false; } } @@ -316,6 +320,8 @@ bool CanViewWithKnownExternalViewer(WindowTab* tab, int cmd) { if (engineKind != nullptr) { if (ev->engineKind != nullptr) { if (ev->engineKind != engineKind) { + logfa("CanViewWithKnownExternalViewer cmd: %d, ev->engineKind '%s' != engineKind '%s'\n", cmd, + ev->engineKind, engineKind); return false; } } @@ -363,8 +369,10 @@ static TempStr FormatParamsTemp(const char* cmdLine, WindowTab* tab) { bool ViewWithKnownExternalViewer(WindowTab* tab, int cmd) { bool canView = CanViewWithKnownExternalViewer(tab, cmd); - ReportIf(!canView); // TODO: with command palette can send un-enforcable command if (!canView) { + // TODO: with command palette can send un-enforcable command + logfa("ViewWithKnownExternalViewer cmd: %d\n", cmd); + ReportIf(!canView); return false; } ExternalViewerInfo* ev = FindExternalViewerInfoByCmd(cmd);