mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 21:05:56 -05:00
Added proper error messages to data processor
This commit is contained in:
@@ -36,7 +36,7 @@ namespace hex::dp {
|
||||
|
||||
[[nodiscard]] Node* getParentNode() { return this->m_parentNode; }
|
||||
|
||||
[[nodiscard]] std::vector<u8>& getOutputData() { return this->m_outputData; }
|
||||
[[nodiscard]] std::optional<std::vector<u8>>& getOutputData() { return this->m_outputData; }
|
||||
private:
|
||||
u32 m_id;
|
||||
IOType m_ioType;
|
||||
@@ -45,7 +45,7 @@ namespace hex::dp {
|
||||
std::map<u32, Attribute*> m_connectedAttributes;
|
||||
Node *m_parentNode;
|
||||
|
||||
std::vector<u8> m_outputData;
|
||||
std::optional<std::vector<u8>> m_outputData;
|
||||
|
||||
friend class Node;
|
||||
void setParentNode(Node *node) { this->m_parentNode = node; }
|
||||
|
||||
@@ -23,6 +23,14 @@ namespace hex::dp {
|
||||
|
||||
virtual void drawNode() { }
|
||||
virtual void process() = 0;
|
||||
|
||||
using NodeError = std::pair<Node*, std::string>;
|
||||
|
||||
void resetOutputData() {
|
||||
for (auto &attribute : this->m_attributes)
|
||||
attribute.getOutputData().reset();
|
||||
}
|
||||
|
||||
private:
|
||||
u32 m_id;
|
||||
std::string m_title;
|
||||
@@ -43,49 +51,71 @@ namespace hex::dp {
|
||||
|
||||
protected:
|
||||
|
||||
std::optional<std::vector<u8>> getBufferOnInput(u32 index) {
|
||||
auto attribute = this->getConnectedInputAttribute(index);
|
||||
|
||||
if (attribute == nullptr || attribute->getType() != Attribute::Type::Buffer)
|
||||
return { };
|
||||
|
||||
attribute->getParentNode()->process();
|
||||
|
||||
auto &outputData = attribute->getOutputData();
|
||||
|
||||
return outputData;
|
||||
[[noreturn]] void throwNodeError(std::string_view message) {
|
||||
throw NodeError(this, message);
|
||||
}
|
||||
|
||||
std::optional<u64> getIntegerOnInput(u32 index) {
|
||||
std::vector<u8> getBufferOnInput(u32 index) {
|
||||
auto attribute = this->getConnectedInputAttribute(index);
|
||||
|
||||
if (attribute == nullptr || attribute->getType() != Attribute::Type::Integer)
|
||||
return { };
|
||||
if (attribute == nullptr)
|
||||
throwNodeError(hex::format("Nothing connected to input '%s'", this->m_attributes[index].getName().data()));
|
||||
|
||||
if (attribute->getType() != Attribute::Type::Buffer)
|
||||
throwNodeError("Tried to read buffer from non-buffer attribute");
|
||||
|
||||
attribute->getParentNode()->process();
|
||||
|
||||
auto &outputData = attribute->getOutputData();
|
||||
|
||||
if (outputData.empty() || outputData.size() < sizeof(u64))
|
||||
return { };
|
||||
else
|
||||
return *reinterpret_cast<u64*>(outputData.data());
|
||||
if (!outputData.has_value())
|
||||
throw std::runtime_error("No data available at connected attribute");
|
||||
|
||||
return outputData.value();
|
||||
}
|
||||
|
||||
std::optional<float> getFloatOnInput(u32 index) {
|
||||
u64 getIntegerOnInput(u32 index) {
|
||||
auto attribute = this->getConnectedInputAttribute(index);
|
||||
|
||||
if (attribute == nullptr || attribute->getType() != Attribute::Type::Float)
|
||||
return { };
|
||||
if (attribute == nullptr)
|
||||
throwNodeError(hex::format("Nothing connected to input '%s'", this->m_attributes[index].getName().data()));
|
||||
|
||||
if (attribute->getType() != Attribute::Type::Integer)
|
||||
throwNodeError("Tried to read integer from non-integer attribute");
|
||||
|
||||
attribute->getParentNode()->process();
|
||||
|
||||
auto &outputData = attribute->getOutputData();
|
||||
|
||||
if (outputData.empty() || outputData.size() < sizeof(float))
|
||||
return { };
|
||||
else
|
||||
return *reinterpret_cast<float*>(outputData.data());
|
||||
if (!outputData.has_value())
|
||||
throw std::runtime_error("No data available at connected attribute");
|
||||
|
||||
if (outputData->size() < sizeof(u64))
|
||||
throw std::runtime_error("Not enough data provided for integer");
|
||||
|
||||
return *reinterpret_cast<u64*>(outputData->data());
|
||||
}
|
||||
|
||||
float getFloatOnInput(u32 index) {
|
||||
auto attribute = this->getConnectedInputAttribute(index);
|
||||
|
||||
if (attribute == nullptr)
|
||||
throwNodeError(hex::format("Nothing connected to input '%s'", this->m_attributes[index].getName().data()));
|
||||
|
||||
if (attribute->getType() != Attribute::Type::Float)
|
||||
throwNodeError("Tried to read float from non-float attribute");
|
||||
|
||||
attribute->getParentNode()->process();
|
||||
|
||||
auto &outputData = attribute->getOutputData();
|
||||
|
||||
if (!outputData.has_value())
|
||||
throw std::runtime_error("No data available at connected attribute");
|
||||
|
||||
if (outputData->size() < sizeof(float))
|
||||
throw std::runtime_error("Not enough data provided for float");
|
||||
|
||||
return *reinterpret_cast<float*>(outputData->data());
|
||||
}
|
||||
|
||||
void setBufferOnOutput(u32 index, std::vector<u8> data) {
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace hex::prv {
|
||||
constexpr static size_t PageSize = 0x1000'0000;
|
||||
|
||||
Provider();
|
||||
virtual ~Provider() = default;
|
||||
virtual ~Provider();
|
||||
|
||||
virtual bool isAvailable() = 0;
|
||||
virtual bool isReadable() = 0;
|
||||
|
||||
Reference in New Issue
Block a user