Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: calebs on March 07, 2021, 11:13:06 pm

Title: bsod when trying to copy canvas to another canvas
Post by: calebs on March 07, 2021, 11:13:06 pm
Hello all. I'm making a program that reprints a ticket and i need to add an qr code to it.
I've installed the lazbarcodes component and droped into the form and filled the text property with the values but the problem starts when i try to copy the canvas of the qr to the printer canvas.
Always giving me a bsod "apc_index_mismatch win32kfull.sys" im windows 10 pro with lazarus 64 bit

Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   YPos, LineHeight, VerticalMargin, nro, ancho, posx, xdp, ydp, alto,imaal, imaan, nroi: Integer;
  4.   SuccessString, titulos, ftitulos, fcabecerapie, fcuerpo, cad, lin, impresora, scant, sdescr, sprec, nloca, nprov, ncodp: String;
  5.   fuente : tfont;
  6.   lineas : tstringlist;
  7.   ftamano, titulostamano, cabecerapietamano, cabecerapietamano2: LongInt;
  8.   enc: Boolean;
  9.   rectt, rectqr: TRect;
  10.   estilo : TTextStyle;
  11.   empresa: tempresa;
  12.   desc : real;
  13.   prec, ivaa: double;
  14.  
  15. begin
  16.     ... more code ...
  17.     with Printer do
  18.     try
  19.       SetPrinter(impresora);
  20.       BeginDoc;
  21.       fuente:=TFont.Create;
  22.       fuente.Name:=ftitulos;
  23.       fuente.Color:=clBlack;
  24.       fuente.Size:=titulostamano;
  25.       fuente.Bold:=true;
  26.       canvas.Font:=fuente;
  27.       LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));
  28.       ypos:=0;
  29.       canvas.TextOut(5,ypos,empresa.razsoc);
  30.       ypos:=ypos+1*LineHeight;
  31.       fuente.Name:=fcabecerapie;
  32.       fuente.Size:=cabecerapietamano;
  33.       fuente.Bold:=false;
  34.       canvas.Font:=fuente;
  35.       LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));
  36.       lineas:=TStringList.Create;
  37.       cad:=listview1.items[listview1.ItemIndex].SubItems[2];
  38.       if (cad=factacte) or (cad=factacon) or (cad=factbcon) or (cad=factbcte) or (cad=factccon) or (cad=factccte) then
  39.         lineas.Add('---FACTURA---')
  40.       else if cad=remventa then
  41.         lineas.Add('---REMITO DE VENTA---')
  42.       else if cad=pedidoventa then
  43.           lineas.Add('---ORDEN DE PEDIDO---');
  44.       lineas.Add('CUIT:'+empresa.cuit+' ING.BR:'+empresa.ingbr);
  45.       lineas.Add('DRI:'+empresa.dri);
  46.       lineas.Add(empresa.domfiscal + ' - TEL:' + empresa.tel1);
  47.     ... more code ...
  48.       cad:='{"ver":<p1>,"fecha":"<p2>","cuit":<p3>,"ptoVta":<p4>,"tipoCmp":<p5>,"nroCmp":<p6>,"importe":<p7>,"moneda":"<p8>","ctz":<p9>,"tipoDocRec":<p10>';
  49.       cad:=cad+',"nroDocRec":<p11>,"tipoCodAut":"<p12>","codAut":<p13>}';
  50.       cad:=StringReplace(cad,'<p1>','1',[]);
  51.       cad:=StringReplace(cad,'<p2>',fechajuntaaiso8601(listview1.items[listview1.ItemIndex].SubItems[7]),[]);
  52.       cad:=StringReplace(cad,'<p3>',empresa.cuit,[]);
  53.       cad:=StringReplace(cad,'<p4>',listview1.Items[listview1.ItemIndex].SubItems[2],[]);
  54.       cad:=StringReplace(cad,'<p5>','001',[]);
  55.       cad:=StringReplace(cad,'<p6>',listview1.Items[listview1.ItemIndex].SubItems[2],[]);
  56.       cad:=StringReplace(cad,'<p7>',listview1.Items[listview1.ItemIndex].SubItems[4],[]);
  57.       cad:=StringReplace(cad,'<p8>','PES',[]);
  58.       cad:=StringReplace(cad,'<p9>','1',[]);
  59.       cad:=StringReplace(cad,'<p10>','80',[]);
  60.       cad:=StringReplace(cad,'<p11>',listview1.Items[listview1.ItemIndex].SubItems[3],[]);
  61.       cad:=StringReplace(cad,'<p12>','E',[]);
  62.       cad:=StringReplace(cad,'<p13>',listview1.items[listview1.ItemIndex].SubItems[6],[]);
  63.       BarcodeQR1.Text:=cad;
  64.       xdp:=printer.XDPI;
  65.       ydp:=printer.YDPI;
  66.       imaal:=BarcodeQR1.Canvas.Height;
  67.       imaan:=BarcodeQR1.canvas.Width;
  68.       ancho:=printer.PaperSize.PaperRect.PhysicalRect.Width;
  69.       posx:=10;
  70.       alto:=ypos+10;
  71.       rectqr:=Rect(0,0,BarcodeQR1.Width-1,BarcodeQR1.Height - 1);
  72.       printer.Canvas.CopyRect(rectqr,BarcodeQR1.canvas,rectqr);                          <<< HERE ALWAYS GIVES ME THE BSOD
  73. //      canvas.CopyRect(Classes.Rect(posx,alto,posx+imaan,alto+imaal),BarcodeQR1.Canvas,classes.Rect(0,0, imaan, imaal));
  74.     finally
  75.       EndDoc;
  76.     end;
  77.   end;
  78. end;                                
  79.  
  80.  
i still don't have clear how to copy the qr image and put it on the printer canvas at specified position but i was in the middle of the research when this happen.
im doing something very very wrong with that sentence?
If i remove that line doesnt hang.

thanks

Ps: if anyone has an example on how can i copy the qr to the printer canvas it would be awesome
Title: Re: bsod when trying to copy canvas to another canvas
Post by: calebs on March 08, 2021, 12:03:28 am
nevermind... replaced that line with this code and everything works ok.
I still like to know what is that i do for cause a bsod everytime with the code above...

Code: Pascal  [Select][+][-]
  1. BarcodeQR1.Text:='https://www.afip.gob.ar/fe/qr/?p='+encodestringbase64(cad);
  2.  
  3.       bmp := TBitmap.Create;
  4.       R := Rect(0, 0, BarcodeQR1.Width, BarcodeQR1.Height);
  5.       r2:= rect(0,ypos+10,BarcodeQR1.Width,ypos+10+BarcodeQR1.Height);
  6.       bmp.SetSize(BarcodeQR1.Width, BarcodeQR1.Height);
  7.       bmp.Canvas.Brush.Color := clWhite;
  8.       bmp.Canvas.FillRect(R);
  9.       BarcodeQR1.PaintOnCanvas(bmp.Canvas, R);
  10.       canvas.CopyRect(r2,bmp.canvas,r);                  

thanks
Title: Re: bsod when trying to copy canvas to another canvas
Post by: ASBzone on March 08, 2021, 12:56:05 am
Always giving me a bsod "apc_index_mismatch win32kfull.sys" im windows 10 pro with lazarus 64 bit

I would suggest that you need to update the video drivers on your system.

Which build of Windows 10?    What video card and drivers?
Title: Re: bsod when trying to copy canvas to another canvas
Post by: calebs on March 17, 2021, 03:35:27 pm
sorry for delay... i have win10x64 20h2 19042.867
radeon HD6870 and latest driver available from amd (its very old)
But i don't think it was a video driver problem
Title: Re: bsod when trying to copy canvas to another canvas
Post by: wp on March 17, 2021, 04:07:00 pm
You should try to condense your code into a small demo program which shows the issue and which you can upload here. It is much easier to help with support by the compiler.
TinyPortal © 2005-2018