Skip to content

Commit

Permalink
Return AvisynthError exception message when plugin loading failed in …
Browse files Browse the repository at this point in the history
…AvisynthPluginInit3
  • Loading branch information
pinterf committed Jan 28, 2023
1 parent 4a223e5 commit 78c0d9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions avs_core/core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,8 @@ bool PluginManager::LoadPlugin(PluginFile &plugin, bool throwOnError, AVSValue *
#endif

// Try to load various plugin interfaces
if (!TryAsAvs26(plugin, result))
std::string avsexception26_message;
if (!TryAsAvs26(plugin, result, avsexception26_message))
{
if (!TryAsAvsC(plugin, result))
{
Expand All @@ -974,7 +975,10 @@ bool PluginManager::LoadPlugin(PluginFile &plugin, bool throwOnError, AVSValue *
plugin.Library = NULL;

if (throwOnError)
Env->ThrowError("'%s' cannot be used as a plugin for AviSynth.", plugin.FilePath.c_str());
if (avsexception26_message.empty())
Env->ThrowError("'%s' cannot be used as a plugin for AviSynth.", plugin.FilePath.c_str());
else
Env->ThrowError("'%s' plugin loading error: %s", plugin.FilePath.c_str(), avsexception26_message.c_str());
else
return false;
}
Expand Down Expand Up @@ -1107,7 +1111,7 @@ std::string PluginManager::PluginLoading() const
return PluginInLoad->BaseName;
}

bool PluginManager::TryAsAvs26(PluginFile &plugin, AVSValue *result)
bool PluginManager::TryAsAvs26(PluginFile &plugin, AVSValue *result, std::string &avsexception_message)
{
extern const AVS_Linkage* const AVS_linkage; // In interface.cpp
#ifdef AVS_POSIX
Expand All @@ -1123,6 +1127,7 @@ bool PluginManager::TryAsAvs26(PluginFile &plugin, AVSValue *result)
#endif

bool success = true;
avsexception_message = "";
if (AvisynthPluginInit3 == NULL)
return false;
else
Expand All @@ -1132,6 +1137,10 @@ bool PluginManager::TryAsAvs26(PluginFile &plugin, AVSValue *result)
try {
*result = AvisynthPluginInit3(Env, AVS_linkage);
}
catch (const AvisynthError& error) {
avsexception_message = error.msg;
success = false;
}
catch (...)
{
success = false;
Expand Down
2 changes: 1 addition & 1 deletion avs_core/core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PluginManager
bool AutoloadExecuted;
bool Autoloading;

bool TryAsAvs26(PluginFile &plugin, AVSValue *result);
bool TryAsAvs26(PluginFile &plugin, AVSValue *result, std::string& avsexception_message);
bool TryAsAvs25(PluginFile &plugin, AVSValue *result);
bool TryAsAvsC(PluginFile &plugin, AVSValue *result);

Expand Down

0 comments on commit 78c0d9f

Please sign in to comment.