Fix crash when moving around certain views

This commit is contained in:
WerWolv 2020-11-11 10:47:02 +01:00
parent 9b6b43356b
commit 9e62685fd1
9 changed files with 38 additions and 32 deletions

View file

@ -22,6 +22,7 @@ add_executable(ImHex
source/views/view_pattern.cpp
source/views/view_pattern_data.cpp
source/views/view_hashes.cpp
source/views/view_entropy.cpp
libs/glad/source/glad.c

View file

@ -17,7 +17,7 @@ namespace hex::lang {
};
explicit ASTNode(Type type) : m_type(type) {}
virtual ~ASTNode() {}
virtual ~ASTNode() = default;
Type getType() { return this->m_type; }

View file

@ -8,16 +8,16 @@ namespace hex::prv {
class FileProvider : public Provider {
public:
FileProvider(std::string_view path);
virtual ~FileProvider();
explicit FileProvider(std::string_view path);
~FileProvider() override;
virtual bool isAvailable() override;
virtual bool isReadable() override;
virtual bool isWritable() override;
bool isAvailable() override;
bool isReadable() override;
bool isWritable() override;
virtual void read(u64 offset, void *buffer, size_t size) override;
virtual void write(u64 offset, void *buffer, size_t size) override;
virtual size_t getSize() override;
void read(u64 offset, void *buffer, size_t size) override;
void write(u64 offset, void *buffer, size_t size) override;
size_t getSize() override;
private:
FILE *m_file;

View file

@ -23,7 +23,7 @@ namespace hex::lang {
std::optional<u64> parseInt(std::string_view string) {
u64 integer = 0;
u8 base = 10;
u8 base;
std::string_view numberData;

View file

@ -27,11 +27,11 @@ namespace hex::prv {
}
bool FileProvider::isReadable() {
return this->m_readable;
return isAvailable() && this->m_readable;
}
bool FileProvider::isWritable() {
return this->m_writable;
return isAvailable() && this->m_writable;
}

View file

@ -1,5 +1,7 @@
#include "views/view_hashes.hpp"
#include "providers/provider.hpp"
#include "utils.hpp"
#include <vector>
@ -16,19 +18,19 @@ namespace hex {
void ViewHashes::createView() {
static bool invalidate = false;
if (!this->m_windowOpen)
return;
static bool invalidate = false;
if (ImGui::Begin("Hashing", &this->m_windowOpen)) {
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
ImGui::NewLine();
if (this->m_dataProvider != nullptr && this->m_dataProvider->isAvailable()) {
ImGui::Combo("Hash Function", &this->m_currHashFunction, HashFunctionNames, sizeof(HashFunctionNames) / sizeof(const char*));
ImGui::Combo("Hash Function", &this->m_currHashFunction, HashFunctionNames,
sizeof(HashFunctionNames) / sizeof(const char *));
ImGui::NewLine();
ImGui::Separator();
@ -115,10 +117,9 @@ namespace hex {
invalidate = true;
}
ImGui::EndChild();
ImGui::End();
}
ImGui::End();
}
void ViewHashes::createMenu() {

View file

@ -1,5 +1,6 @@
#include "views/view_hexeditor.hpp"
#include "providers/provider.hpp"
#include "providers/file_provider.hpp"
namespace hex {

View file

@ -48,23 +48,24 @@ namespace hex {
if (!this->m_windowOpen)
return;
ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
if (ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None)) {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
auto size = ImGui::GetWindowSize();
size.y -= 50;
ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size, ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit,
[](ImGuiInputTextCallbackData* data) -> int {
auto _this = static_cast<ViewPattern*>(data->UserData);
auto size = ImGui::GetWindowSize();
size.y -= 50;
ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size, ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit,
[](ImGuiInputTextCallbackData* data) -> int {
auto _this = static_cast<ViewPattern*>(data->UserData);
_this->parsePattern(data->Buf);
_this->parsePattern(data->Buf);
return 0;
}, this
);
return 0;
}, this
);
ImGui::PopStyleVar(2);
ImGui::PopStyleVar(2);
}
ImGui::End();
}

View file

@ -1,5 +1,7 @@
#include "views/view_pattern_data.hpp"
#include "providers/provider.hpp"
#include <cstring>
namespace hex {
@ -48,8 +50,8 @@ namespace hex {
}
ImGui::EndChild();
ImGui::End();
}
ImGui::End();
}
void ViewPatternData::createMenu() {