Bonjour à tous,

Je suis en train de développer une application en c++(.net) et je recontre un problème pour un bout de code.

L'erreur qui m'est signalée est la suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
HEAP CORRUPTION DETECTED : after normal block (#126564) at 0X051E2DA0 CRTdetected that the application wrote to memory after end of heap buffer.
Voici le bout de code qui pose problème:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 
	double getDistanceProfile(array<ProfileElement^, 1>^ profileValues, int typeNumber, int pointNumber)
	{
		LaVectorDouble g(numberPointsPerProfile);
		LaVectorDouble gbar(numberPointsPerProfile);
		LaVectorDouble diff(numberPointsPerProfile);
		LaVectorDouble temp(1,numberPointsPerProfile);
		LaVectorDouble dist(1);
		LaGenMatDouble s(numberPointsPerProfile, numberPointsPerProfile);
 
		double MahalanobisDistance = 0.0;
 
		for(int i=0; i<numberPointsPerProfile; i++)
		{
			g(i) = profileValues[i]->getPixelValue();
		}
 
		gbar = toLaVectorDouble(modeleProfil->getMeanModelProfile(typeNumber, pointNumber));
		s = toLaGenMatDouble(modeleProfil->getCovMat(typeNumber, pointNumber));
 
		s.operator *=(10000000.0);
 
		LaVectorLongInt piv = LaVectorLongInt(s.size(0));
		LaVectorDouble work = LaVectorDouble(s.size(0));
 
		diff = g - gbar;
 
		try
		{
			LUFactorizeIP(s,piv);
			LaLUInverseIP(s,piv,work);
 
			Blas_Mat_Trans_Mat_Mult(diff, s, temp, 1.0, 0.0);
			Blas_Mat_Mat_Mult(temp, diff, dist, 1.0, 0.0);
 
			MahalanobisDistance = dist(0);
		}
		catch(System::Runtime::InteropServices::SEHException^ e)
		{
			int permut;
			double temp;
			double temppos;
 
			LaGenMatDouble vectp(numberPointsPerProfile, numberPointsPerProfile);
			LaGenMatDouble vectpSorted(numberPointsPerProfile, numberPointsPerProfile);
			LaVectorDouble valp(numberPointsPerProfile);
			LaVectorDouble valpPos(numberPointsPerProfile);
 
			for(int s=0; s<numberPointsPerProfile; s++)
			{
				valpPos(s) = s;
			}
 
			vectp = toLaGenMatDouble(modeleProfil->getVectPropres(typeNumber, pointNumber));
			valp = toLaVectorDouble(modeleProfil->getValPropres(typeNumber, pointNumber));
 
			do
			{
				permut = 0;
				for(int h=0; h<numberPointsPerProfile; h++)
				{
					if(valp(h) < valp(h+1))
					{
						temp = valp(h+1);
						valp(h+1) = valp(h);
						valp(h) = temp;
 
						temppos = valpPos(h+1);
						valpPos(h+1) = valpPos(h);
						valpPos(h) = temppos;
 
						permut = 1;
					}
				}
			}while(permut == 1);
 
			for(int w=0; w<numberPointsPerProfile; w++)
			{
				for(int f=0; f<numberPointsPerProfile; f++)
				{
					vectpSorted(w,f) = vectp(w,valpPos(f));
				}
			}
 
			int posi=0;
			for(int h=0; h<numberPointsPerProfile; h++)
			{
				if(valp(h)<0.0000000000000001)
				{
					if(h>0)
						posi=h-1;
					break;
				}
				else
				{
					if(h==numberPointsPerProfile-1)
					{
						posi = numberPointsPerProfile-1;
					}
				}
			}
 
			LaGenMatDouble vectpSortedSign(numberPointsPerProfile, posi+1);
			LaVectorDouble valpSign(posi+1);
			LaVectorDouble quot(posi+1);
			LaVectorDouble bg(posi+1);
 
			for(int f=0; f<numberPointsPerProfile; f++)
			{
				for(int d=0; d<=posi; d++)
				{
					vectpSortedSign(f,d) = vectpSorted(f,d);
					valpSign(d) = valp(d);
				}
			}
 
			Blas_Mat_Trans_Mat_Mult(vectpSortedSign, diff, bg, 1.0, 0.0);
 
			LaVectorDouble bgsquare(1);
			LaVectorDouble diffsquare(1);
 
			Blas_Mat_Trans_Mat_Mult(bg, bg, bgsquare, 1.0, 0.0);
			Blas_Mat_Trans_Mat_Mult(diff, diff, diffsquare, 1.0, 0.0);
 
			double Rsquare = diffsquare(0) - bgsquare(0);
 
			for(int g=0; g<=posi; g++)
			{
				quot(g) = Math::Pow(bg(g), 2) / valpSign(g);
			}
 
			double sommeQuot = 0.0;
 
			for(int d=0; d<=posi; d++)
			{
				sommeQuot += quot(d);
			}
 
			MahalanobisDistance = -(sommeQuot + (2*Rsquare/valpSign(posi)));
			//return MahalanobisDistance;
		}
		return MahalanobisDistance;	
	}
Si je passe dans le Try, il n'y a pas de problème. Par contre à chaque fois que je passe dans le catch, la même erreur se répète. J'ai vu sur internet que de telles erreurs surgissaient quand on était en dehors des limites d'un tableau par exemple mais ici je n'ai pas trouvé de tel problème. J'utilise la librairie Lapack++. Dans mon cas, numberPointsPerProfile vaut 7 et posi vaut 3.

Merci pour votre aide