Topic: releasing AVS_ScriptEnvironment fails after loading svpflow dlls
Hi there,
I'm currently writing a small GUI for AviSynth especially to visualize the differences between native recorded and estimated frames. So I came across this wonderfull project which fits my needs perfectly.
Loading AviSynth scripts and receiving frames with my application works fine. But I have trouble releasing AviSynths ScriptEnvironment (avs_delete_script_environment(AVS_ScriptEnvironment *)). The debugger throws: "Exception (first Chance) 0xB0DA355A in minimal.exe: 0xC0000008: An invalid handle was specified". I tracked the problem down to the point where the SVPflow dlls (svpflow1.dll, svpflow2.dll) are loaded. Once both dlls are loaded the invocation of avs_delete_script_environment fails and the application crashes (other external avs filter (e.g ffms2.dll) don't fail). I wrote a minimal example that should reproduce this problem. Can someone give me some hints to solve this?
Some background infomation:
- I'm using Visual Studio Ultimate 2013, Windows 8.1 (64bit)
- replaced avisynth.dll in SysWOW64 folder with latest AviSynth2.5.8(SVP edition) dll
- using AviSynths C API
- linked against avisynth.lib
- svpflow_cpu.dll, svpflow_gpu.dll, svpflow1.dll, svpflow2.dll are in the same folder
#include "stdafx.h"
#include "avisynth_c.h"
#include <windows.h>
#include <stdio.h>
#define PATH_AVS_PLUGIN_SVPFLOW1 "C:\\Users\\Bjoern\\Desktop\\minimal\\minimal\\svpflow1.dll"
#define PATH_AVS_PLUGIN_SVPFLOW2 "C:\\Users\\Bjoern\\Desktop\\minimal\\minimal\\svpflow2.dll"
int _tmain(int argc, _TCHAR* argv[])
{
typedef AVS_ScriptEnvironment*(_stdcall *avs_create_script_environment)(int);
typedef void(_stdcall *avs_delete_script_environment)(AVS_ScriptEnvironment *);
typedef AVS_Value(_stdcall *avs_invoke)(AVS_ScriptEnvironment *, const char *, AVS_Value, const char**);
typedef void(_stdcall *avs_release_value)(AVS_Value);
HMODULE dll;
AVS_ScriptEnvironment *env;
dll = LoadLibrary(L"avisynth.dll");
if(!dll) {
fprintf(stderr, "Cannot load avisynth.dll");
return 1;
}
avs_create_script_environment p_create = (avs_create_script_environment) GetProcAddress(dll, "avs_create_script_environment");
if(!p_create) {
return 1;
}
env = p_create(AVISYNTH_INTERFACE_VERSION);
if(env == NULL) {
fprintf(stderr, "Cannot create CreateScriptEnvironment");
return 1;
}
avs_invoke p_invoke = (avs_invoke) GetProcAddress(dll, "avs_invoke");
if(!p_invoke) {
return 1;
}
AVS_Value ret = p_invoke(env, "LoadPlugin", avs_new_value_string(PATH_AVS_PLUGIN_SVPFLOW1), NULL);
if(avs_is_error(ret)) {
fprintf(stderr, "%s", avs_as_error(ret));
return 1;
}
ret = p_invoke(env, "LoadPlugin", avs_new_value_string(PATH_AVS_PLUGIN_SVPFLOW2), NULL);
if(avs_is_error(ret)) {
fprintf(stderr, "%s", avs_as_error(ret));
return 1;
}
avs_release_value p_release = (avs_release_value) GetProcAddress(dll, "avs_release_value");
if(!p_release) {
return 1;
}
p_release(ret);
avs_delete_script_environment p_delete_script_env = (avs_delete_script_environment) GetProcAddress(dll, "avs_delete_script_environment");
if (!p_delete_script_env) {
return 1;
}
p_delete_script_env(env); // IT FAILS HERE
FreeLibrary(dll);
return 0;
}