View Full Version : Throw error on frame processing in C
Youka
2nd January 2016, 15:12
The C++ API of Avisynth (http://avisynth.nl/index.php/Filter_SDK/Cplusplus_API) allows throwing errors with environment method ThrowError (http://avisynth.nl/index.php/Filter_SDK/Cplusplus_API#ThrowError). The C API (http://avisynth.nl/index.php/Avisynth_Plugin_Development_in_C) handles errors in another way: returning an AVS value of type error by filter call.
But what's with errors on frame processing (in get frame callback)? ThrowError works as expected, but how to raise an error in C?
Setting error in AVS_FilterInfo stops any processing, but the display size doesn't change and no error message is drawn (as normally expected).
raffriff42
2nd January 2016, 23:25
Amazing that this information is not readily available. I will take a guess.
1. Don't throw errors outside your DLL at all. Read this advice:
http://avisynth.nl/index.php/AviSynth%2B#AviSynth_Plugin_Writing_Tips
2. I think you do the same as Avisynth does - in case of error, return a null pointer. It's the 'C' way./*
* src\core\avisynth_c.cpp(173)
*/
extern "C"
AVS_VideoFrame * AVSC_CC avs_get_frame(AVS_Clip * p, int n)
{
p->error = 0;
try {
PVideoFrame f0 = p->clip->GetFrame(n,p->env);
AVS_VideoFrame * f;
new((PVideoFrame *)&f) PVideoFrame(f0);
return f;
} catch (AvisynthError err) {
p->error = err.msg;
return 0;
}
}
Groucho2004
3rd January 2016, 00:09
Amazing that this information is not readily available. I will take a guess.
1. Don't throw errors outside your DLL at all. Read this advice:
http://avisynth.nl/index.php/AviSynth%2B#AviSynth_Plugin_Writing_Tips
2. I think you do the same as Avisynth does - in case of error, return a null pointer. It's the 'C' way./*
* src\core\avisynth_c.cpp(173)
*/
extern "C"
AVS_VideoFrame * AVSC_CC avs_get_frame(AVS_Clip * p, int n)
{
p->error = 0;
try {
PVideoFrame f0 = p->clip->GetFrame(n,p->env);
AVS_VideoFrame * f;
new((PVideoFrame *)&f) PVideoFrame(f0);
return f;
} catch (AvisynthError err) {
p->error = err.msg;
return 0;
}
}
No.
C doesn't support exceptions or try/catch statements.
One might try something like this (http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html).
raffriff42
3rd January 2016, 01:55
I speak not of try/catch or setjmp/longjmp, but of 'C' style error signaling (in the case of avs_get_frame: return pointer to frame, or null on error). The try/catch I quoted was internal to the function (in C++ land) and was not part of the Avisynth C interface.
Groucho2004
3rd January 2016, 11:34
I speak not of try/catch or setjmp/longjmp, but of 'C' style error signaling (in the case of avs_get_frame: return pointer to frame, or null on error). The try/catch I quoted was internal to the function (in C++ land) and was not part of the Avisynth C interface.
I see what you mean. Worth a try, I guess.
raffriff42
3rd January 2016, 13:20
Worth a try, I guess.I caught that.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.