[fpc-pascal] AggPas / PTCGraph dynamic memory allocation

James Richters james at productionautomation.net
Mon Nov 13 17:39:08 CET 2017


>>     ClockBuffer_With_Time:=ClockBuffer_original;
>
>That seems fine.
>
>>     AggClockbuffer^:=ClockBuffer_With_Time^+3*Sizeof(Longint);   //Set AggClockBuffer to be 3 Longints past ClockBuffer_with_time
>
>This seems wrong. Try changing that to the following:
>
> AggClockbuffer := ClockBuffer_With_Time + (3*Sizeof(Longint));

Now I have a new issue...  It's just failing with either return code 253 or 255  but no runtime error.. I put in some writeln's to see where the problem is.  Here below my test program.  It executes the Writeln('5'); but not the Writeln('6') in between is 
         aggclock^.Text(2 ,19,FormatDateTime('hh:nn:ssam/pm',Now));  I moved this line up to where the aggclock^fillcolor commands are, and it fails up there too...

Any ideas?



{$mode objfpc}{$H+}

uses
  shlobj,
  ptcgraph,
  ptccrt,
  sysutils,
  agg_pixfmt_rgb_packed,
  agg_2D;

const
  RGB_WIDTH =2;
  Clock_W = 120;
  Clock_h = 40;

Var
   address1,address2      : longint;
   Newtime,Oldtime        : Double;
   Bufsize                : Longint;
   gd,gm                  : smallint;
   aggClock               : Agg2D_ptr;
   Font2use,FontPath      : Array[0..MaxPathLen] of Char;
   clockbuffer_Original   : ^Byte;
   clockbuffer_with_time  : ^Byte;
   Aggclockbuffer         : ^Byte;

Begin
   gd:=d16Bit;
   gm:=m800x600;
   ptcgraph.Initgraph(gd,gm,'');
   SHGetSpecialFolderPath(0,FontPath,CSIDL_FONTS,false);
   font2use:=FontPath+'\Lucon.ttf';
   bufSize:=ImageSize((GetMaxX-4)-Clock_W, 4 , GetMaxX-4, 4+Clock_H);
   GetMem(ClockBuffer_Original, bufSize);   { Allocate memory on heap }
   GetImage((GetMaxX-4)-Clock_W+1,  4, GetMaxX-4,  4+Clock_H-1, ClockBuffer_original^);
   ClockBuffer_With_Time:=ClockBuffer_original;
   Writeln('1');
   Putimage((GetMaxX-4)-Clock_W,  4, Clockbuffer_With_Time^, normalPut);
   Writeln('1.5');
   AggClockbuffer := ClockBuffer_With_Time + (3*Sizeof(Longint));
   Writeln('2');
   New(aggClock , Construct(@pixfmt_rgb565));
   aggClock^.attach(@AggClockbuffer,Clock_W, Clock_H, -Clock_W * RGB_WIDTH);
   aggclock^.Font(font2use ,12 );
   aggclock^.LineColor($FF ,$FF ,$00 );
   aggclock^.FillColor($FF ,$FF ,$60 );
   Writeln('3');

Repeat
   Newtime:=now;
   If Trunc(Newtime*346600)<>Trunc(Oldtime*345600) Then  //update every 1/4 second
      Begin
         OldTime:=NewTime;
         Writeln('4');
         ClockBuffer_With_Time:=ClockBuffer_original;
         Writeln('5');
         aggclock^.Text(2 ,19,FormatDateTime('hh:nn:ssam/pm',Now));
         Writeln('6');
         Putimage((GetMaxX-4)-Clock_W,  4, Clockbuffer_With_Time^, normalPut);
         Writeln('7');
      End;
until KeyPressed;
End.




More information about the fpc-pascal mailing list