diff --git a/easy_profiler_core/reader.cpp b/easy_profiler_core/reader.cpp index 480fc37..b27d3e6 100644 --- a/easy_profiler_core/reader.cpp +++ b/easy_profiler_core/reader.cpp @@ -1016,12 +1016,25 @@ extern "C" PROFILER_API profiler::block_index_t fillTreesFromStream(std::atomic< } usedMemorySize -= static_cast(profiler::Bookmark::BaseSize) - 1; - if (usedMemorySize > 1) + if (usedMemorySize > 0) { stringBuffer.resize(usedMemorySize); + read(inStream, stringBuffer.data(), usedMemorySize); - inStream.read(stringBuffer.data(), usedMemorySize); - bookmark.text = stringBuffer.data(); + if (stringBuffer.back() != 0) + { + stringBuffer.resize(stringBuffer.size() + 1); + stringBuffer.back() = 0; + + _log << "Bad bookmark description:\n\"" << const_cast(stringBuffer.data()) + << "\"\nWhich is not zero terminated string.\nLast symbol is: '" + << const_cast(stringBuffer.data() + stringBuffer.size() - 2) << "'"; + + return 0; + } + + if (usedMemorySize != 1) + bookmark.text = stringBuffer.data(); } else { diff --git a/profiler_gui/blocks_graphics_view.cpp b/profiler_gui/blocks_graphics_view.cpp index 4807bb6..d3a3d4b 100644 --- a/profiler_gui/blocks_graphics_view.cpp +++ b/profiler_gui/blocks_graphics_view.cpp @@ -413,15 +413,20 @@ bool BackgroundItem::mouseMove(const QPointF& scenePos) if (prev != m_bookmark) { - if (m_bookmark < bookmarks.size()) - qApp->setOverrideCursor(QCursor(Qt::PointingHandCursor)); + if (!profiler_gui::is_max(m_bookmark)) + { + if (qApp->overrideCursor() == nullptr || qApp->overrideCursor()->shape() != Qt::PointingHandCursor) + qApp->setOverrideCursor(QCursor(Qt::PointingHandCursor)); + } else + { qApp->restoreOverrideCursor(); + } emit bookmarkChanged(m_bookmark); update(); } - if (m_bookmark < bookmarks.size()) + if (!profiler_gui::is_max(m_bookmark)) { if (!m_idleTimer.isActive()) m_idleTimer.start(); @@ -455,7 +460,7 @@ bool BackgroundItem::mouseMove(const QPointF& scenePos) bool BackgroundItem::mousePress(const QPointF& scenePos) { - m_bButtonPressed = m_bookmark < EASY_GLOBALS.bookmarks.size() && contains(scenePos); + m_bButtonPressed = !profiler_gui::is_max(m_bookmark) && contains(scenePos); delete m_tooltip; m_tooltip = nullptr; @@ -470,7 +475,7 @@ bool BackgroundItem::mouseRelease(const QPointF& scenePos) m_bButtonPressed = false; - if (m_bookmark < EASY_GLOBALS.bookmarks.size()) + if (!profiler_gui::is_max(m_bookmark)) { auto& bookmarks = EASY_GLOBALS.bookmarks; std::sort(bookmarks.begin(), bookmarks.end(), @@ -492,7 +497,7 @@ bool BackgroundItem::mouseDoubleClick(const QPointF& scenePos) if (!contains(scenePos)) return false; - if (m_bookmark < EASY_GLOBALS.bookmarks.size()) + if (!profiler_gui::is_max(m_bookmark)) { qApp->restoreOverrideCursor(); auto editor = new BookmarkEditor(m_bookmark, false, sceneView->parentWidget()); @@ -515,7 +520,7 @@ bool BackgroundItem::mouseDoubleClick(const QPointF& scenePos) mouseMove(scenePos); - if (m_bookmark < bookmarks.size()) + if (!profiler_gui::is_max(m_bookmark)) { qApp->restoreOverrideCursor(); auto editor = new BookmarkEditor(m_bookmark, true, sceneView->parentWidget()); @@ -534,7 +539,7 @@ void BackgroundItem::mouseLeave() if (m_idleTimer.isActive()) m_idleTimer.stop(); - if (m_bookmark < EASY_GLOBALS.bookmarks.size()) + if (!profiler_gui::is_max(m_bookmark)) { profiler_gui::set_max(m_bookmark); qApp->restoreOverrideCursor(); diff --git a/profiler_gui/main_window.cpp b/profiler_gui/main_window.cpp index c6d87b6..ed35118 100644 --- a/profiler_gui/main_window.cpp +++ b/profiler_gui/main_window.cpp @@ -1509,7 +1509,7 @@ void MainWindow::showEvent(QShowEvent* show_event) void MainWindow::closeEvent(QCloseEvent* close_event) { - if (m_bNetworkFileRegime || EASY_GLOBALS.has_local_changes) + if (!m_bCloseAfterSave && (m_bNetworkFileRegime || EASY_GLOBALS.has_local_changes)) { // Warn user about unsaved network information and suggest to save const auto result = Dialog::question(this, "Unsaved session" @@ -1518,6 +1518,13 @@ void MainWindow::closeEvent(QCloseEvent* close_event) if (result == QMessageBox::Yes) { onSaveFileClicked(true); + if (m_reader.isSaving() && m_progress != nullptr) + { + // Wait until finish and close + m_bCloseAfterSave = true; + close_event->ignore(); + return; + } } else if (result == QMessageBox::Cancel) { @@ -2156,6 +2163,11 @@ void MainWindow::onFileReaderTimeout() { onSavingFinish(); closeProgressDialogAndClearReader(); + if (m_bCloseAfterSave) + { + setEnabled(false); + QTimer::singleShot(1500, this, &This::close); + } } else { diff --git a/profiler_gui/main_window.h b/profiler_gui/main_window.h index 4b2c9bf..b5f6553 100644 --- a/profiler_gui/main_window.h +++ b/profiler_gui/main_window.h @@ -302,6 +302,7 @@ protected: uint16_t m_lastPort = 0; bool m_bNetworkFileRegime = false; bool m_bOpenedCacheFile = false; + bool m_bCloseAfterSave = false; public: