FIX: crash when delete media file in PrinterFileSystem

Change-Id: I9783bbfc9c9979b6da662b917b6f5cf4db04aa69
This commit is contained in:
chunmao.guo 2022-10-09 10:46:52 +08:00 committed by Lane.Wei
parent e325214cb6
commit 633d14e711
2 changed files with 16 additions and 11 deletions

View file

@ -188,8 +188,10 @@ void ImageGrid::UpdateLayout()
if (!m_file_sys) return; if (!m_file_sys) return;
wxSize size = GetClientSize(); wxSize size = GetClientSize();
wxSize mask_size{0, 60 * em_unit(this) / 10}; wxSize mask_size{0, 60 * em_unit(this) / 10};
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
mask_size.y = 20 * em_unit(this) / 10; mask_size.y = 20 * em_unit(this) / 10;
size.y -= mask_size.y;
}
int cell_width = m_cell_size.GetWidth(); int cell_width = m_cell_size.GetWidth();
int cell_height = m_cell_size.GetHeight(); int cell_height = m_cell_size.GetHeight();
int ncol = (size.GetWidth() - cell_width + m_image_size.GetWidth()) / cell_width; int ncol = (size.GetWidth() - cell_width + m_image_size.GetWidth()) / cell_width;
@ -365,13 +367,16 @@ void ImageGrid::paintEvent(wxPaintEvent& evt)
size_t Slic3r::GUI::ImageGrid::firstItem(wxSize const &size, wxPoint &off) size_t Slic3r::GUI::ImageGrid::firstItem(wxSize const &size, wxPoint &off)
{ {
int size_y = size.y;
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE)
size_y -= m_mask.GetHeight();
int offx = (size.x - (m_col_count - 1) * m_cell_size.GetWidth() - m_image_size.GetWidth()) / 2; int offx = (size.x - (m_col_count - 1) * m_cell_size.GetWidth() - m_image_size.GetWidth()) / 2;
int offy = (m_row_offset + 1 < m_row_count || m_row_count == 0) ? int offy = (m_row_offset + 1 < m_row_count || m_row_count == 0) ?
m_cell_size.GetHeight() - m_image_size.GetHeight() - m_row_offset * m_cell_size.GetHeight() / 4 + m_row_offset / 4 * m_cell_size.GetHeight() : m_cell_size.GetHeight() - m_image_size.GetHeight() - m_row_offset * m_cell_size.GetHeight() / 4 + m_row_offset / 4 * m_cell_size.GetHeight() :
size.y - (size.y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight() * m_cell_size.GetHeight(); size_y - (size_y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight() * m_cell_size.GetHeight();
int index = (m_row_offset + 1 < m_row_count || m_row_count == 0) ? int index = (m_row_offset + 1 < m_row_count || m_row_count == 0) ?
m_row_offset / 4 * m_col_count : m_row_offset / 4 * m_col_count :
((m_file_sys->GetCount() + m_col_count - 1) / m_col_count - (size.y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight()) * m_col_count; ((m_file_sys->GetCount() + m_col_count - 1) / m_col_count - (size_y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight()) * m_col_count;
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE)
offy += m_mask.GetHeight(); offy += m_mask.GetHeight();
off = wxPoint{offx, offy}; off = wxPoint{offx, offy};

View file

@ -320,7 +320,7 @@ void PrinterFileSystem::DeleteFilesContinue()
std::vector<size_t> indexes; std::vector<size_t> indexes;
std::vector<std::string> names; std::vector<std::string> names;
for (size_t i = 0; i < m_file_list.size(); ++i) for (size_t i = 0; i < m_file_list.size(); ++i)
if ((m_file_list[i].flags & FF_SELECT) && !m_file_list[i].name.empty()) { if ((m_file_list[i].flags & FF_DELETED) && !m_file_list[i].name.empty()) {
indexes.push_back(i); indexes.push_back(i);
names.push_back(m_file_list[i].name); names.push_back(m_file_list[i].name);
if (names.size() >= 64) if (names.size() >= 64)
@ -338,7 +338,7 @@ void PrinterFileSystem::DeleteFilesContinue()
FILE_DEL, req, nullptr, FILE_DEL, req, nullptr,
[indexes, names, this](int, Void const &) { [indexes, names, this](int, Void const &) {
// TODO: // TODO:
for (size_t i = indexes.size() - 1; i >= 0; --i) for (size_t i = indexes.size() - 1; i != size_t(-1); --i)
FileRemoved(indexes[i], names[i]); FileRemoved(indexes[i], names[i]);
SendChangedEvent(EVT_FILE_CHANGED); SendChangedEvent(EVT_FILE_CHANGED);
DeleteFilesContinue(); DeleteFilesContinue();
@ -363,11 +363,11 @@ void PrinterFileSystem::DownloadNextFile(std::string const &path)
SendChangedEvent(EVT_DOWNLOAD, index, m_file_list[index].name); SendChangedEvent(EVT_DOWNLOAD, index, m_file_list[index].name);
struct Download struct Download
{ {
int index; size_t index;
std::string name; std::string name;
std::string path; std::string path;
boost::filesystem::ofstream ofs; boost::filesystem::ofstream ofs;
boost::uuids::detail::md5 boost_md5; boost::uuids::detail::md5 boost_md5;
}; };
std::shared_ptr<Download> download(new Download); std::shared_ptr<Download> download(new Download);
download->index = index; download->index = index;
@ -412,9 +412,9 @@ void PrinterFileSystem::DownloadNextFile(std::string const &path)
return result; return result;
}, },
[this, download](int result, Progress const &data) { [this, download](int result, Progress const &data) {
if (download->index >= 0) if (download->index != size_t(-1))
download->index = FindFile(download->index, download->name); download->index = FindFile(download->index, download->name);
if (download->index >= 0) { if (download->index != size_t(-1)) {
int progress = data.size * 100 / data.total; int progress = data.size * 100 / data.total;
if (result > CONTINUE) if (result > CONTINUE)
progress = -2; progress = -2;