Log in

View Full Version : Can someone look over this and tell me if I'm doing something wrong/inadvisable?


wonkey_monkey
7th June 2020, 16:37
https://pastebin.com/w5h1ksny

This is some code for a basic caching filter I wrote to speed up a random access filter.

I'm currently using it as part of a complex script, and for some reason it seems to be causing a crash (I also can't rule out the child filter yet, but removing the call to this filter also stops the crash).

And by "crash" I mean the host program, either VirtualDub, AvsMeter64, or my own, just disappears completely without so much as an exception.

I'm calling it with:

FrameCache(0, 40, true)

which should cause it to preload and cache frames 0-40 of the passed clip. This should only need about 128mb of RAM (I've got 24Gb of it to play with).

One odd thing I've noticed is that, for some reason, during the caching filter's constructor the passed ("child", I still think that's poor terminology though!) clip's GetFrame is called three times in a row for frame 0, without ever returning to the calling point (line 33 in the file). It only gets called once for all the other frames.

Usually it crashes after the first or second GetFrame for frame 0 of the child clip, but it's one of those weird ones where adding more debugging output lines seems to stop the crash happening.

Edit: running AvsMeter64, because it crashes memory usage peaks at about 1.5Gb, so it doesn't seem to be a memory problem.

Anyone got any clues? Is what I'm doing liable to be an abuse of PVideoFrame?

real.finder
7th June 2020, 17:03
there are FrameCache in warpsharp, so it's better to change the function name

StainlessS
7th June 2020, 17:34
Wonkey, I dont see any real probs, but

//#ssS if (start < 0 || end < 0 || end < start) env->ThrowError("FrameCache: bad start/end value(s)"); // Original line
if (start < 0 || end < start || end >= num_frames) env->ThrowError("FrameCache: bad start/end value(s)");



AVSValue __cdecl Create_FrameCache(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new FrameCache(
args[0].AsClip(),
args[1].AsInt(0),
args[2].AsInt(0),
args[3].AsBool(), //sss # No default
env
);
}


EDIT: Maybe add

FrameCache::FrameCache(PClip _child, int _start, int _end, bool _immediate, IScriptEnvironment* env) : GenericVideoFilter(_child), start(_start), end(_end), immediate(_immediate), cache(NULL) {


EDIT: You could also output debug stuff to narrow down where problem resides.

int __cdecl dprintf(char* fmt, ...) {
char printString[2048]="Wonkey_Test: "; // This must be nul termed eg "Hello: ", at very least char printString[2048]="".
char *p=printString;
for(;*p++;);
--p; // @ null term
va_list argp;
va_start(argp, fmt);
vsprintf(p, fmt, argp);
va_end(argp);
for(;*p++;);
--p; // @ null term
if(printString == p || p[-1] != '\n') {
p[0]='\n'; // append n/l if not there already
p[1]='\0';
}
OutputDebugString(printString);
return int(p-printString); // strlen printString
}



dprintf("We got to position %d so far",position);


EDIT: Above dprintf() may require below to avoid M$ compiler warning [before M$ headers inclusion].

#define _CRT_SECURE_NO_WARNINGS

wonkey_monkey
7th June 2020, 21:45
EDIT: You could also output debug stuff to narrow down where problem resides.

Well that's part of the problem. The crash seems to happen, usually, in the middle of some compiled machine code from an otherwise very stable plugin, so it's hard to work out what's going wrong. It's one of those weird ones where it seems to be caused by a specific combination of filters.