Attribuer de la memoire

Le_clezio Messages postés 5 Date d'inscription lundi 13 octobre 2003 Statut Membre Dernière intervention 25 octobre 2003 - 21 oct. 2003 à 13:51
cs_Zeroc00l Messages postés 367 Date d'inscription lundi 1 avril 2002 Statut Membre Dernière intervention 11 février 2010 - 14 janv. 2005 à 09:28
j'ai ce code:
Getmem(Ptemp,3*MyImage.Width* MyImage.height*sizeOf(integer));

et

j'ai cette erreur "project graphics031.exe raised exception class EAccessViolation with message 'Access vioaltion at address 004703AA in module 'graphics031.exe'. Read of address 00000000'. Process stopped....

je ne sais pas quoi fare pour l'eviter.

3 réponses

cs_Bestiol Messages postés 833 Date d'inscription dimanche 6 janvier 2002 Statut Membre Dernière intervention 3 novembre 2005 1
21 oct. 2003 à 16:45
C'est un peu bizarre étant donné que le code que tu mets ne me semble pas contenir d'erreur....

Pourrais-tu donner plus de renseignements ?!
La déclaration de PTemp, par exemple, le code qu'il y a autour de ça... Es-tu bien sûr que ce soit cette ligne là qui plante ?

Bonne prog' !
[mailto:bestiol@cario.fr Bestiol.]

Visitez mon site : :big)
Delphi vu par Bestiol (bientôt terminé !)
0
Le_clezio Messages postés 5 Date d'inscription lundi 13 octobre 2003 Statut Membre Dernière intervention 25 octobre 2003
25 oct. 2003 à 12:45
merci de ton attention
voici le code entier de la procedure, elle est tres longue et getmem est juste au debut.

procedure TConvolution.ButtonApplyClick(Sender: TObject);
var
   PTemp1, PImg1, PTemp, PImg, PFilt, PFilt1 : ^integer;
   Scan : PByteArray;
   x, y, posFil, posImg, posTemp, x1, y1, C, filterWi,
   filterHe, min , max, s : integer;

   SFilter: array of integer;

begin
     {Shows how to allocate memory dynamically -
     3 because we want red, green and blue,
     then the number of pixels,
     then the size of each thing (real) we want}
     //storage of the calculated values of pixel
     GetMem(PTemp, 3*MyImage.Width*MyImage.Height*Sizeof(Integer));
     //Storage of the values of pixel of the Image
     GetMem(PImg, 3*MyImage.Width*MyImage.Height*Sizeof(Integer));

  min := 0;
  max := 0;
  Screen.Cursor := crHourGlass;  // Let user know we're busy...

{initialise the filter}
  filterWi:=Matrice.ColCount ;
  filterHe:=Matrice.RowCount ;
  s:= round(filterHe/2 - 0.5);      // to know how many pixel not used on the side

  SetLength(Sfilter,(filterWi*filterHe)); //set the size of the array

  for y:=0 to filterHe-1 do begin
        for  x:=0 to filterWi-1 do begin               // loads filter values
                posFil:=y*filterWi+x ;                    //  from matrice
                Sfilter[posFil] :=StrToInt(Matrice.Cells[x,y]);
        end;
  end;
  PFilt := @Sfilter[0];

//-------------store the pixel value in the memory--------------//

     {Shows how to access each colour component}
      for y:=0 to MyImage.Height-1 do
      begin
         Scan:=MyImage.ScanLine[y];
         for x:=0 to MyImage.Width-1 do
         begin
             posImg:=(y*MyImage.Width + x)*3;
             PImg1:=PImg;
             inc(PImg1,posImg);
             PImg1^:=Scan[x*3];         {blue pixel}
             inc(PImg1);
             PImg1^:=Scan[x*3+1];        {green pixel}
             inc(PImg1);
             PImg1^:=Scan[x*3+2]        {red pixel}
         end;
      end;

//----------------Apply the filter----------------------//

      //manage the position in the memory for image and the temporary file.
     for y:=0 to MyImage.Height - filterHe do
     begin
         for x:=0 to MyImage.Width - filterWi do
         begin
         posImg:=(y*MyImage.Width+x)*3;
         posTemp:=((y*MyImage.Width+x)+ (MyImage.Width+ s))*3;
         PImg1:=PImg;
         PTemp1:= PTemp;
         inc(PImg1,posImg);
         {the line on sides is not used,
         s1 is the pixels on the side not used}
         inc(PTemp1,posTemp);

/// do this part for each color blue (C = 0), green(C=1), red(C=2)
            for C:=0 to 2 do
            begin
            PTemp1^:= 0;
            //manage the position in the filter
                for y1:=0 to filterHe-1 do
                begin
                    for  x1:=0 to filterWi-1 do
                    begin
                    posFil:=y1*filterWi+x1 ;
                    Pfilt1:=Pfilt;
                    inc(Pfilt1,posFil);
                    inc(PImg1,posFil + C);
                    PTemp1^:= PTemp1^+ PImg1^ * Pfilt1^;

                    // record min and max intensities
                    if PTemp1^< min  then
                       min := PTemp1^;

                    if PTemp1^> max  then
                       min := PTemp1^;
                    end;
                end;
                inc(PTemp1);
            end;
        end;
    end;

//-----------------Calculate the new intensity of the pixel-------------//

 // do this part for each color blue (C = 0), green(C=1), red(C=2)
    for C:=0 to 2 do
    begin
        for y:=0 to MyImage.Height - filterHe do
        begin
                for x:=0 to MyImage.Width - filterWi do
                begin
                posImg:=(y*MyImage.Width+x)*3 + C;
                PosTemp:=((MyImage.Width + s)+(y*MyImage.Width+x))*3 + C;
                PImg1:=PImg;
                PTemp1:=(PTemp);
                inc(PImg1,posImg);
                inc(PTemp1,posTemp);
                PImg1^ :=(PTemp1^ - min)* 255;
                end;
         end;
    end;

//----------------DISPLAY THE NEW VALUE-----------------------//

      for y:=0 to MyImage.Height-1 do begin
         Scan:=MyImage.ScanLine[y];
         for x:=0 to MyImage.Width-1 do begin
             posImg:=(y*MyImage.Width+x)*3;
             PImg1:=PImg;
             inc(PImg1,posImg);
             Scan[x*3]:= round(PImg1^/(max-min));         {blue pixel}
             inc(PImg1);
             Scan[x*3+1]:= round(PImg1^/(max-min));       {green pixel}
             inc(PImg1);
             Scan[x*3+2]:= round(PImg1^/(max-min));       {red pixel}
         end;
      end;

    {Free the memory}
     Dispose(PTemp);
     Dispose(PImg);

      {redraw the image after its been changed}

    ImgPro.Image1.Canvas.Draw(0,0,MyImage);

    Screen.Cursor := crDefault;

    end;
0
cs_Zeroc00l Messages postés 367 Date d'inscription lundi 1 avril 2002 Statut Membre Dernière intervention 11 février 2010
14 janv. 2005 à 09:28
Personellement moi aussi j'ai un probleme de pointeur.

Je construit un graphe suivant un parsing d'une chaine de caractere.

A un moment donne sur une certaine ligne j'ai l'instruction :

New(T); ou T est un pointeur de classe

Ensuite je fais T := MonType.SonContructeur(SesParametres);

etc .. tout se passe bien



puis je reboucle et repasse sur le New(T)

La quand je fais un pas a pas le pc met une seconde a reflechir et m'affiche le message d'erreur suivant :



Titre de la fenetre : "Debugger Fault Application"

Contenu : '.../.../Monprojet.exe' fault with message 'access
violation at 0x004059c1 : write of adress 0x00030dec'. Process stopped.
USes stepor to continue'



et j'entre directement dans le code assembleur

euh on peut m'expliquer comment New peut planter ?

Je n'alloue que 200 Ko au max avant d'arriver au moment ou l'instruction plante

(et a priori tout mes objet sont correctement initialise et bien detruit !)



Si vous avez une idée merci bcp d'avacne !

-={[ Zeroc00l ]}=-
0
Rejoignez-nous