View Single Post
Old 11th September 2012, 09:04   #1  |  Link
sscheidegger
Registered User
 
Join Date: Sep 2012
Posts: 14
Memory leak when using env->NewVideoFrame(vi)

Hi all

I'm trying to develop an interface to use some avisynth filters in an NLE in MS Visual Studio 2005. I got it to work apart from a memory leak which I'm trying to fix for a while now.

Code:
void myNLEclass::myNLEplugin()
{
  IScriptEnvironment* env = CreateScriptEnvironment(AVISYNTH_INTERFACE_VERSION);
  env->AddFunction("myNLEsource", "i", Create_myNLEsource, myNLEclassInstance);
  PClip myclip = env->Invoke("myNLEsource",0).AsClip();
  PVideoFrame myframe = myclip->GetFrame(_myNLEtime, env);
  // Here I plan to apply some avisynth filters and hand over the result to my NLE later
  delete myframe;
  delete myclip;
  delete env;
}
I also implemented the Avisynth plugin myNLEsource which sets the vi properties, creates a new frame using env->NewVideoFrame(vi) and gets the video frame from myNLEclassInstance.
Everything works fine if I leave away the three delete statements, but the used memory is growing with every processed frame until it crashes. If I put the three delete statements, it breaks at delete myframe. I get "Windows has triggered a breakpoint in..." and it breaks in new.cpp at the line "while ((p = malloc(size)) == 0)".

In the beginning I linked to avisynth dynamically using:
Code:
avsDLL = LoadLibrary("avisynth.dll");	
IScriptEnvironment* (__stdcall * CreateScriptEnvironment)(int version) =
                              (IScriptEnvironment*(__stdcall *)(int)) GetProcAddress(_avsDLL, "CreateScriptEnvironment");
I read that it could be a problem if the memory for the frame is allocated in a library which was compiled in release version and trying to use delete in debug version. So compiled everything in release version, but it didn't help.
Then I read that it might be a problem allocating the memory in a dll which was compiled with a different version of VS. So I compiled avisynth myself and linked statically adding avisynth.lib to my project. But still it doesn't work.

Any ideas what I'm doing wrong? Any suggestions how to free the memory?

Thanks a lot for any help!

Stefan

Last edited by Guest; 11th September 2012 at 14:18. Reason: fix wide post
sscheidegger is offline   Reply With Quote