fix: Subcommands not working at all on Linux

This commit is contained in:
WerWolv 2023-07-21 14:12:08 +02:00
parent 3149183450
commit e5a793e8de
3 changed files with 4 additions and 12 deletions

View File

@ -24,11 +24,6 @@ namespace hex {
std::function<void(const std::vector<std::string>&)> callback;
};
struct SubCommandList {
hex::SubCommand *subCommands;
size_t size;
};
class Plugin {
public:
explicit Plugin(const std::fs::path &path);
@ -58,7 +53,7 @@ namespace hex {
using GetCompatibleVersionFunc = const char *(*)();
using SetImGuiContextFunc = void (*)(ImGuiContext *);
using IsBuiltinPluginFunc = bool (*)();
using GetSubCommandsFunc = SubCommandList* (*)();
using GetSubCommandsFunc = void* (*)();
#if defined(OS_WINDOWS)
HMODULE m_handle = nullptr;

View File

@ -39,10 +39,7 @@
#define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \
extern std::vector<hex::SubCommand> g_subCommands; \
extern "C" [[gnu::visibility("default")]] hex::SubCommandList getSubCommands() { \
return hex::SubCommandList { \
g_subCommands.data(), \
g_subCommands.size() \
}; \
extern "C" [[gnu::visibility("default")]] void* getSubCommands() { \
return &g_subCommands; \
} \
std::vector<hex::SubCommand> g_subCommands

View File

@ -155,7 +155,7 @@ namespace hex {
std::span<SubCommand> Plugin::getSubCommands() const {
if (this->m_getSubCommandsFunction != nullptr) {
auto result = this->m_getSubCommandsFunction();
return { result->subCommands, result->size };
return *reinterpret_cast<std::vector<SubCommand>*>(result);
} else
return { };
}