Log in

View Full Version : Unrecognised Exception due to code in constructor


vcmohan
8th June 2005, 03:59
I am trying to put some initialization code in the constructor of my plugin. I find that if I have that code and I have an error situation (in this case wrong format) then instead of a ThrowError message I get a Unrecognised Exception. This is so even though the code is after Throw Error message. If I move that peice of code either to the GetFrame method or to the Create_Function area it works fine. I could not localize that problem to either the first or second loop eventhough the first one seems to have a larger effect? Is the compiler VC++ 6 the problem or some thing else. My code is below and the relevant portions are in the comments area.


class Gauss : public GenericVideoFilter {

// bool k3x3; // true for 3 X 3 size, false for 5X5 size
// double sd; // standard deviation
bool uu,vv; // whether u and v planes also to be used in yuy2 and yv12 formats.

int kern[5];
int ksize;

public:
//Definition of function
Gauss(PClip _child,
int _ksize, bool _uu, bool _vv,
int k0, int k1, int k2, int k3, int k4,

IScriptEnvironment* env) ;

virtual ~Gauss(){}; //destructor
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);

};
/*************************************************
* The following is the implementation
* of the defined functions.
*************************************************/
//Here is the acutal constructor code used

Gauss::Gauss(PClip _child,
int _ksize, bool _uu, bool _vv,
int k0, int k1, int k2, int k3, int k4,

IScriptEnvironment* env) :
GenericVideoFilter(_child),ksize(_ksize),uu(_uu),vv(_vv)
// kern[0](k0),kern[1](k1),kern[2](k2),kern[3](k3),kern[4](k4)

{
kern[0]=(k0);
kern[1]=(k1);
kern[2]=(k2);
kern[3]=(k3);
kern[4]=(k4);

if( !vi.IsYUY2() && !vi.IsRGB32() )
env->ThrowError("Gauss: This color format is not yet supported");


/* ksize=k3x3?3:5;
double sum=0;
for(int i=0;i<ksize;i++)
{
kr[i]=pow(2.71828, -(0.5*(i-ksize/2)*(i-ksize/2))/(sd*sd))/(sd*sqrt(6.2831853));

sum+=kr[i];
}

for(i=0;i<ksize;i++)
kern[i]=1024*kr[i]/sum ; // so that we only do integer multiplications and a final div by bit shift


*/

}


also the compiler gives an error [ if I use the following commented out line in constructor

kern[0](k0),kern[1](k1),kern[2](k2),kern[3](k3),kern[4](k4)

stickboy
8th June 2005, 05:21
What version of AviSynth? Wasn't the error handling stuff kind of broken in 2.5.6, or has that been fixed?

mg262
8th June 2005, 05:22
initialise sd?

IanB
8th June 2005, 10:52
VCMohan,

kern[0](k0),kern[1](k1),kern[2](k2),kern[3](k3),kern[4](k4)no you can't do this, possible "kern({k0, k1, k2, k3, k4})" but I doubt it with VC6.

Is the compiler VC++ 6 the problem or ...You are being bitten by my most unfavourite compiler bug. If you have a look at the generated assembler you will find the exception handling code refers to a table built on the stack that the main line code never initialises. **** M$ :angry:

The most successful workaround I have found is to wrap your whole routine in atry {
<your code>
}
catch (...) {
throw;
}

Good luck.
IanB

vcmohan
8th June 2005, 14:50
Well at least good to know that the problem is not in my coding.

While on the subject of MS VC++ 6, I have been trying to use stack.
I have a
#include <stack>
at the begining.
In the code I use a declaration
stack < int> offset;

While I am coding I get auto word filling support for all of my later statements such as
offset.pop();
offset.push(100);
etc;

when I compile got an error at the declaration statement line stating stack is not declared. and next int is an unexpected token. I also found that a name 'ref' I was using as
unsigned char ref=128;
gave an error saying it was declared as double. Changing name eliminated error.

I found in text/ rasterization <vector> is used and not stack. So I could not get help from seeing that code.

tsp
8th June 2005, 15:26
do you use: using namespace std; else you will have to use this:
std::stack<int> offset;

Bidoche
8th June 2005, 23:06
Better avoid the using declaration and use the qualified name instead.
You never know what you may bring from a whole namespace...

I found in text/ rasterization <vector> is used and not stack. So I could not get help from seeing that code.text/rasterizer from 3.0 branch ?
I do not use stack there, but names are always qualified std::vector<X>

Here is the doc I use about the STL: http://www.sgi.com/tech/stl/table_of_contents.html
Maybe it could help you

vcmohan
9th June 2005, 03:10
Thanks I will try std::
It should do.

vcmohan
10th June 2005, 03:51
Yes. It worked fine with std::
Silly I forgot this.

mg262
10th June 2005, 06:43
Also, in that first code fragment, you don't initialise the member variable sd anywhere that I can see...

Sorry the earlier reply was so cryptic - speech rec. wasn't working so I couldn't type much.

edit:
add to that: if you want to initialise kern using the standard constructor syntax, you can use std::vector<int> kern; instead of an array. then if you replace

int k0, int k1, int k2, int k3, int k4,

with

vector<int> k,

you can change

kern[0](k0),kern[1](k1),kern[2](k2),kern[3](k3),kern[4](k4)

into the legitimate

kern(k)

of course you'd still have to initialise k in the calling function, so I'm not sure whether you'd prefer this!

vcmohan
11th June 2005, 03:05
The code you see is in its present working state. Now Initialization and computing coefficients is done in create_ section. So sd is no longer required in the class. It was initialized in class section when I tried to compute coefficients in the constructor part. My problem is not in computing or initializing. If I put the computing coefficients in constructor, then in case I have an ThrowError condition, it is reporting unrecognised exception. If there is no error condition it computes fine. If I remove that computing code from constructor ThrowError works fine.

Regarding Kern array since there are only 5 elements I did not bother to use vector form.