Hey, I'm struggling against the following problem. I wrote a simple gaus algorithm, but AFTER it is done executing (succesfuly), pretty much any next attempt to alocate memory crashes the program and gives me the following error:
"Windows has triggetred a breakpoint in ...
This may be due to a corruption of heap, which indicates...
and displays malloc.c to me.
Any ideas what im doing wrong?
Thanks in advance
The code:
#ifndef __GAUS_H_INCLUDED__
#define __GAUS_H_INCLUDED__
#include "Grid.h"
#include <math.h>
class Gaus
{
private:
public:
Gaus ()
{
}
Gaus ( GPA * Source, GPA * Result)
{
CallGaus(Source,Result);
}
void CallGaus( GPA * Source, GPA * Result )
{
int xa, xe, ya, ye, sx, sy=0, T, s;
Punkt P;
s=(*Source).X;
Punkt* R1;
Punkt* R2;
Punkt* R3;
R1 = new Punkt[s];
R2 = new Punkt[s];
R3 = new Punkt[s];
xa=0; ya=0; xe=(*Source).X; ye=(*Source).Y;
sy=ya;
for (sx = xa; sx < xe; sx++)
{ P=(*Source)[sx][sy]; R2[sx]=P; }
for (sx = xa; sx < xe; sx++)
{ P=(*Source)[sx][sy+1]; R3[sx]=P; }
for (sy=ya+1; sy < ye-1; sy++) {
int sy1=sy+1;
int xa1=xa+1;
R1=R2;
R2=R3;
R3[sx]=(*Source)[xa][sy1];
R3[sx+1]=(*Source)[xa1][sy1];
int r2=int(R1[xa].R+2*R2[xa].R+R3[xa].R);
int G2=int(R1[xa].G+2*R2[xa].G+R3[xa].G);
int B2=int(R1[xa].B+2*R2[xa].B+R3[xa].B);
int r3=int(R1[xa1].R+2*R2[xa1].R+R3[xa1].R);
int G3=int(R1[xa1].G+2*R2[xa1].G+R3[xa1].G);
int B3=int(R1[xa1].B+2*R2[xa1].B+R3[xa1].B);
for (T=(xa-1);T<(xe-1);T++)
{
int T1=T+1;
R3[T1]=(*Source)[T1][sy1];
int r1=r2;
int G1=G2;
int B1=B2;
r2=r3; G2=G3; B2=B3;
r3=int(R1[T1].R+2*R2[T1].R+R3[T1].R);
G3=int(R1[T1].G+2*R2[T1].G+R3[T1].G);
B3=int(R1[T1].B+2*R2[T1].B+R3[T1].B);
int rr=(r1+2*r2+r3)/16;
int gg=(G1+2*G2+G3)/16;
int bb=(B1+2*B2+B3)/16;
P.R=rr;
P.G=gg;
P.B=bb;
(*Result).WriteSecure(T, sy, &P);
}
}
}
~Gaus()
{
}
};
#endif