Skip to content

Commit 9cda1f8

Browse files
authored
Merge pull request #20 from Aemony/capture_rotated
Fixed crash when deleting files from elsewhere
2 parents cdcc742 + 8491212 commit 9cda1f8

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

include/utility/image.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ struct skiv_image_directory_s {
365365
struct fl_s {
366366
fd_s* getActiveFile (void)
367367
{
368-
return (_ptr != nullptr) ? _ptr : nullptr;
368+
return _it._Ptr;
369369
}
370370

371371
std::vector<fd_s> getList (void)
@@ -376,15 +376,20 @@ struct skiv_image_directory_s {
376376
void setList (std::vector<fd_s> list)
377377
{
378378
_list = std::move(list);
379-
_it = _list.begin();
380-
_ptr = _it._Ptr;
379+
380+
if (_list.empty())
381+
_list.push_back({ L"", L"", WIN32_FIND_DATA { } });
382+
383+
_it = _list.begin();
381384
}
382385

383386
void clear (void)
384387
{
385388
_list.clear();
386-
_it = _list.begin();
387-
_ptr = nullptr;
389+
390+
_list.push_back({ L"", L"", WIN32_FIND_DATA { } });
391+
392+
_it = _list.begin();
388393
}
389394

390395
bool empty (void)
@@ -403,7 +408,6 @@ struct skiv_image_directory_s {
403408
private:
404409
std::vector<fd_s> _list;
405410
std::vector<fd_s>::iterator _it;
406-
fd_s* _ptr;
407411
} fileList;
408412

409413
//std::wstring orig_path; // Holds a cached copy of cover.path

src/tabs/viewer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,11 +2965,11 @@ SKIF_UI_Tab_DrawViewer (void)
29652965
}
29662966

29672967
// Identify when the folder was changed outside of the app
2968-
//PLOG_VERBOSE << "_current_folder.watch was signaled! Delay checking the folder for another 5000 ms...";
2968+
//PLOG_VERBOSE << "_current_folder.watch was signaled! Delay checking the folder for another 500 ms...";
29692969
if (_current_folder.watch.isSignaled (_current_folder.folder_path))
29702970
dwLastSignaled = SKIF_Util_timeGetTime();
29712971

2972-
if (dwLastSignaled != 0 && dwLastSignaled + 5000 < SKIF_Util_timeGetTime())
2972+
if (dwLastSignaled != 0 && dwLastSignaled + 500 < SKIF_Util_timeGetTime())
29732973
{
29742974
if (! _current_folder.fileList.fileDeleted)
29752975
_current_folder.workerThread (true);
@@ -2988,7 +2988,7 @@ SKIF_UI_Tab_DrawViewer (void)
29882988
PLOG_VERBOSE << "_current_folder.fileList.getActiveFile(): " << _current_folder.fileList.getActiveFile()->path;
29892989

29902990
// If the selected file was changed from within _current_folder, also update dragDroppedFilePath
2991-
if (_current_folder.fileList.getActiveFile() != nullptr &&
2991+
if (! _current_folder.fileList.getActiveFile()->path.empty() &&
29922992
cover.file_info.filename != _current_folder.fileList.getActiveFile()->filename)
29932993
dragDroppedFilePath = _current_folder.fileList.getActiveFile()->path;
29942994

@@ -3000,7 +3000,7 @@ SKIF_UI_Tab_DrawViewer (void)
30003000
// Only apply changes to the scaling method if we actually have an image loaded
30013001
if (cover.pRawTexSRV.p != nullptr)
30023002
{
3003-
if (_current_folder.fileList.getActiveFile() != nullptr && ! _current_folder.fileList.getActiveFile()->path.empty() &&
3003+
if (! _current_folder.fileList.getActiveFile()->path.empty() &&
30043004
ImGui::GetKeyData (ImGuiKey_Delete)->DownDuration == 0.0f) // Delete - Delete the opened image
30053005
_DeleteImage ();
30063006

src/utility/image.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4048,11 +4048,12 @@ skiv_image_directory_s::reset (void)
40484048
void
40494049
skiv_image_directory_s::fl_s::setImage (const std::wstring& path)
40504050
{
4051+
_it = _list.begin();
4052+
40514053
if (_list.empty())
40524054
return;
40534055

4054-
_it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; });
4055-
_ptr = _it._Ptr;
4056+
_it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; });
40564057
}
40574058

40584059
std::wstring
@@ -4074,7 +4075,6 @@ skiv_image_directory_s::fl_s::nextImage (void)
40744075
else
40754076
std::advance (_it, 1);
40764077

4077-
_ptr = _it._Ptr;
40784078
return _it->path;
40794079
}
40804080

@@ -4097,7 +4097,6 @@ skiv_image_directory_s::fl_s::prevImage (void)
40974097
else
40984098
std::advance (_it, -1);
40994099

4100-
_ptr = _it._Ptr;
41014100
return _it->path;
41024101
}
41034102

@@ -4115,23 +4114,19 @@ skiv_image_directory_s::fl_s::deleteImage (void)
41154114
if (_it->path.empty() && ! _list.empty())
41164115
prevImage();
41174116

4118-
_ptr = _it._Ptr;
4119-
41204117
return _it->path;
41214118
}
41224119

41234120
// Find the position of the image in the current folder
41244121
void
41254122
skiv_image_directory_s::fl_s::updateFileIterator (const std::wstring& path)
41264123
{
4127-
_it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; });
4128-
41294124
// If the file was removed from File Explorer, reset to first item
41304125
// TODO: Fix proper file tracking so we can detect removed files and just go to one of the nearby ones
4131-
if (_it->path.empty() && ! _list.empty())
4132-
_it = _list.begin();
4126+
_it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; });
41334127

4134-
_ptr = _it._Ptr;
4128+
if (_it == _list.end())
4129+
_it = _list.begin();
41354130
}
41364131

41374132
int

0 commit comments

Comments
 (0)