1
0
mirror of synced 2024-12-18 02:25:57 +01:00

fix: Multiple race conditions with pattern sorting

This commit is contained in:
WerWolv 2024-10-22 16:20:08 +02:00
parent 101c7a36fb
commit 3739bcc40c
10 changed files with 23 additions and 12 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ cmake-build-*/
build*/
local/
venv/
.cache/
*.mgc
*.kdev4

View File

@ -32,6 +32,7 @@ include("${IMHEX_BASE_FOLDER}/cmake/ide_helpers.cmake")
# Basic compiler and cmake configurations
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include("${IMHEX_BASE_FOLDER}/cmake/build_helpers.cmake")
# Setup project

@ -1 +1 @@
Subproject commit a210503daf9f906578ec3c31484e489e5980933a
Subproject commit 432904c30bc2db346799afe2fa46e0984a49a9e6

View File

@ -1322,8 +1322,6 @@ void TextEditor::EnterCharacter(ImWchar aChar, bool aShift) {
auto coord = GetActualCursorCoordinates();
u.mAddedStart = coord;
assert(!mLines.empty());
if (aChar == '\n') {
InsertLine(coord.mLine + 1);
auto &line = mLines[coord.mLine];

View File

@ -74,7 +74,7 @@ namespace hex {
&& FcPatternGetString(font, FC_FAMILY, 0, &fullName) != FcResultMatch) {
continue;
}
registerFont(reinterpret_cast<const char *>(fullName), reinterpret_cast<const char *>(file));
}
@ -123,7 +123,7 @@ namespace hex {
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
#if defined(GLFW_WAYLAND_APP_ID)
glfwWindowHintString(GLFW_WAYLAND_APP_ID, "imhex");
glfwWindowHintString(GLFW_WAYLAND_APP_ID, "imhex");
#endif
}
@ -190,4 +190,4 @@ namespace hex {
}
#endif
#endif

View File

@ -251,7 +251,7 @@ namespace hex::plugin::builtin {
PerProvider<TextEditor::Coordinates> m_cursorPosition;
PerProvider<std::optional<pl::core::err::PatternLanguageError>> m_lastEvaluationError;
PerProvider<std::vector<pl::core::err::CompileError>> m_lastCompileError;
PerProvider<std::vector<const pl::core::ast::ASTNode*>> m_callStack;
PerProvider<const std::vector<std::unique_ptr<pl::core::ast::ASTNode>>*> m_callStack;
PerProvider<std::map<std::string, pl::core::Token::Literal>> m_lastEvaluationOutVars;
PerProvider<std::map<std::string, PatternVariable>> m_patternVariables;
PerProvider<std::map<u64, pl::api::Section>> m_sections;

View File

@ -9,7 +9,7 @@ namespace hex::plugin::builtin {
void registerPatternLanguagePragmas() {
ContentRegistry::PatternLanguage::addPragma("base_address", [](const pl::PatternLanguage &runtime, const std::string &value) {
ContentRegistry::PatternLanguage::addPragma("base_address", [](pl::PatternLanguage &runtime, const std::string &value) {
auto baseAddress = strtoull(value.c_str(), nullptr, 0);
ImHexApi::Provider::get()->setBaseAddress(baseAddress);
@ -27,4 +27,4 @@ namespace hex::plugin::builtin {
});
}
}
}

View File

@ -1343,8 +1343,8 @@ namespace hex::plugin::builtin {
};
TextEditor::ErrorMarkers errorMarkers;
if (!m_callStack->empty()) {
for (const auto &frame : *m_callStack | std::views::reverse) {
if (!(*m_callStack)->empty()) {
for (const auto &frame : **m_callStack | std::views::reverse) {
auto location = frame->getLocation();
std::string message;
if (location.source->source == pl::api::Source::DefaultSource) {
@ -1806,7 +1806,7 @@ namespace hex::plugin::builtin {
if (!m_lastEvaluationResult) {
*m_lastEvaluationError = runtime.getEvalError();
*m_lastCompileError = runtime.getCompileErrors();
*m_callStack = reinterpret_cast<const std::vector<const pl::core::ast::ASTNode *> &>(runtime.getInternals().evaluator->getCallStack());
*m_callStack = &runtime.getInternals().evaluator->getCallStack();
}
TaskManager::doLater([code] {

View File

@ -130,5 +130,6 @@ namespace hex::ui {
std::function<void(const pl::ptrn::Pattern *)> m_hoverCallback = [](const pl::ptrn::Pattern *) { };
pl::gen::fmt::FormatterArray m_formatters;
u64 m_lastRunId = 0;
};
}

View File

@ -1214,6 +1214,16 @@ namespace hex::ui {
}
void PatternDrawer::draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, const pl::PatternLanguage *runtime, float height) {
if (runtime == nullptr) {
this->reset();
} else {
auto runId = runtime->getRunId();
if (runId != m_lastRunId) {
this->reset();
m_lastRunId = runId;
}
}
std::scoped_lock lock(s_resetDrawMutex);
m_hoverCallback(nullptr);