Recent

Author Topic: ThorVG - test (lightweight vector graphics engine)  (Read 4042 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 1118
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #15 on: February 09, 2026, 09:05:07 am »
I also get an Access violation on a Win10 A4 AMD Laptop, yet on an Intel Win11 laptop all compiles and runs well.

AMD access error at:

 r := tvg_engine_init(4);

unit1.pas(36,3) Note: Local variable "r" is assigned but never used

and at:
 
tvg_animation_set_frame(tvgAnimation, frame_count * progress/duration);

I even tried running the working Intel compiled exe on the AMD laptop and get Invalid floating point operation.

Access violation could possibly be how AMD CPU treats floats?

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3.  
  4. interface
  5.  
  6. uses
  7.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,thorvg_capi, Math;
  8.  
  9. type
  10.  
  11.   { TForm1 }
  12.  
  13.   TForm1 = class(TForm)
  14.     Label1: TLabel;
  15.     PaintBox1: TPaintBox;
  16.     Timer1: TTimer;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormDestroy(Sender: TObject);
  19.     procedure PaintBox1Paint(Sender: TObject);
  20.     procedure Timer1Timer(Sender: TObject);
  21.   private
  22.     tvgCanvas: Tvg_Canvas;
  23.     tvgPaint: Tvg_Paint;
  24.     tvgAnimation: Tvg_Animation;
  25.     progress: Single;
  26.     duration: Single;
  27.     frame_count: Single;
  28.     b: TBitmap;
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. procedure TForm1.FormCreate(Sender: TObject);
  39. var
  40.   r: Tvg_Result;
  41.   Mask1: TFPUExceptionMask;
  42. begin
  43.   b:=TBitmap.Create;
  44.   b.PixelFormat := pf32bit;
  45.   //b.SetSize(PaintBox1.Width, PaintBox1.Height);
  46.   b.Width:= PaintBox1.Width;
  47.   b.Height:= PaintBox1.Height;
  48.  
  49.     Mask1 := SetExceptionMask(GetExceptionMask + [exOverflow,exZeroDivide,exInvalidOp]);
  50.     try
  51.        r := tvg_engine_init(4);
  52.     finally
  53.         SetExceptionMask(Mask1);
  54.     end;
  55.  
  56.  
  57.   tvgCanvas := tvg_swcanvas_create(TVG_ENGINE_OPTION_DEFAULT);
  58.   tvg_swcanvas_set_target(tvgCanvas, PUInt32(b.RawImage.Data), PaintBox1.Width, PaintBox1.Width, PaintBox1.Height, TVG_COLORSPACE_ABGR8888S);
  59.  
  60.   tvgAnimation:=tvg_lottie_animation_new();
  61.   tvgPaint:=tvg_animation_get_picture(tvgAnimation);
  62.   tvg_picture_load(tvgPaint, 'cat.json');
  63.   tvg_animation_get_duration(tvgAnimation, @duration);
  64.   tvg_animation_get_total_frame(tvgAnimation, @frame_count);
  65.   tvg_picture_set_size(tvgPaint, PaintBox1.Width, PaintBox1.Height);
  66.  
  67.   tvg_canvas_add(tvgCanvas, tvgPaint);
  68.  
  69.   Timer1.Enabled:=True;
  70. end;
  71.  
  72. procedure TForm1.FormDestroy(Sender: TObject);
  73. begin
  74.  b.Free;
  75. end;
  76.  
  77. procedure TForm1.PaintBox1Paint(Sender: TObject);
  78. var
  79.     Mask2: TFPUExceptionMask;
  80. begin
  81.   b.BeginUpdate;
  82.  
  83.     Mask2 := SetExceptionMask(GetExceptionMask + [exOverflow,exZeroDivide,exInvalidOp]);
  84.     try
  85.        tvg_animation_set_frame(tvgAnimation, frame_count * progress/duration);
  86.     finally
  87.        SetExceptionMask(Mask2);
  88.     end;
  89.  
  90.     tvg_canvas_update(tvgCanvas);
  91.     tvg_canvas_draw(tvgCanvas, True);
  92.     tvg_canvas_sync(tvgCanvas);
  93.  
  94.   b.EndUpdate(True);
  95.  
  96.   PaintBox1.Canvas.Draw(0,0,b);
  97. end;
  98.  
  99. procedure TForm1.Timer1Timer(Sender: TObject);
  100. begin
  101.   progress:=progress + Timer1.Interval*(1.0/1000.0);
  102.  
  103.   if progress>duration then progress:=0.0;
  104.  
  105.   PaintBox1.Invalidate;
  106. end;
  107.  
  108. end.
« Last Edit: February 09, 2026, 09:41:08 am by Boleeman »

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #16 on: February 09, 2026, 10:14:47 am »
I also get an Access violation
Is it AccessViolation? Or is it “Invalid floating point operation” as shown in your screenshot?

At the very beginning of Form.Create, try simply masking all these exceptions for verification purposes:
Code: Pascal  [Select][+][-]
  1. SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);

As for AMD or Intel, all processors have their own bugs, although I'm not sure if this is a manifestation of a hardware or microcode bug
I may seem rude - please don't take it personally

Boleeman

  • Hero Member
  • *****
  • Posts: 1118
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #17 on: February 09, 2026, 10:36:10 am »
OK I did a test to see if the DLL is loading and found that thorvg.dll is not loading on my AMD laptop.

Not sure if someone can recompile the thorvg.dll DLL on an AMD laptop and upload?


Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   r: Tvg_Result;
  4.   hThorVG: TLibHandle = 0;
  5. begin
  6.   b:=TBitmap.Create;
  7.   b.PixelFormat := pf32bit;
  8.   //b.SetSize(PaintBox1.Width, PaintBox1.Height);
  9.   b.Width:= PaintBox1.Width;
  10.   b.Height:= PaintBox1.Height;
  11.  
  12.       // r := tvg_engine_init(4);
  13.  
  14.       hThorVG := LoadLibrary('thorvg.dll');
  15.       if hThorVG = 0 then
  16.         raise Exception.Create('thorvg.dll not found');
  17.  
  18.  if not Assigned(tvg_engine_init) then
  19.   raise Exception.Create('tvg_engine_init is NIL');
  20.  
  21. if not Assigned(tvg_swcanvas_create) then
  22.   raise Exception.Create('tvg_swcanvas_create is NIL');
  23.  
  24. if not Assigned(tvg_swcanvas_set_target) then
  25.   raise Exception.Create('tvg_swcanvas_set_target is NIL');
  26.  
  27.   tvgCanvas := tvg_swcanvas_create(TVG_ENGINE_OPTION_DEFAULT);
  28.   tvg_swcanvas_set_target(tvgCanvas, PUInt32(b.RawImage.Data),  PaintBox1.Width * 4, PaintBox1.Width, PaintBox1.Height, TVG_COLORSPACE_ABGR8888S);
  29.  
  30.   tvgAnimation:=tvg_lottie_animation_new();
  31.   tvgPaint:=tvg_animation_get_picture(tvgAnimation);
  32.   tvg_picture_load(tvgPaint, 'cat.json');
  33.   tvg_animation_get_duration(tvgAnimation, @duration);
  34.   tvg_animation_get_total_frame(tvgAnimation, @frame_count);
  35.   tvg_picture_set_size(tvgPaint, PaintBox1.Width, PaintBox1.Height);
  36.  
  37.   tvg_canvas_add(tvgCanvas, tvgPaint);
  38.  
  39.   Timer1.Enabled:=True;
  40. end;  


ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #18 on: February 09, 2026, 10:58:11 am »
thorvg.dll is not loading on my AMD laptop
You are probably compiling a 32-bit application, but the library is 64-bit, so it won't work

You need to compile a 64-bit application, then the library will load

I don't plan to deploy a C++ build system myself for now, but I understand that the author of the library is also involved in this thread. Perhaps if he sees this message, we can ask him to create more different versions of the library on GitHub releases: Win_x86, Win_x86_64, Linux_x86_64 (maybe even Arm)?

I still don't think it's an AMD CPU issue
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #19 on: February 09, 2026, 11:06:32 am »
@Booleman
I also see that you haven't changed the constant TVG_COLORSPACE_ABGR8888S to TVG_COLORSPACE_ARGB8888S

(BGR -> RGB)

With the constant from my first post in this thread, the colors come out “flipped”
I may seem rude - please don't take it personally

BildatBoffin

  • New Member
  • *
  • Posts: 47
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #20 on: February 09, 2026, 11:22:01 am »
About linux, is there an API for X11, e.g something in the vein of https://www.cairographics.org/manual/cairo-XLib-Surfaces.html ?

Boleeman

  • Hero Member
  • *****
  • Posts: 1118
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #21 on: February 09, 2026, 11:37:40 am »
OK I changed to TVG_COLORSPACE_ARGB8888S

I installed Visual Studio 2026 Community Edition and compiled on my AMD computer.

I think it was missing DLL dependencies, such as outdated (or, conversely, missing old versions) of the VCRedist runtime, as I used your thorvg.dll

( also compiled the c code using meson and cmake,
it compiled OK but I could not locate the thorvg-1.dll in the build directory/folder
In the meson log.txt it said: Command line for building ['src\\thorvg-1.dll'] is long, using a response file )

Anyhow,
The code now compiles without error using Lazarus 64Bit compiler on my AMD laptop and the exe runs successfully.

Hooray.
« Last Edit: February 09, 2026, 06:20:41 pm by Boleeman »

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #22 on: February 09, 2026, 11:40:59 am »
About linux, is there an API for X11, e.g something in the vein of https://www.cairographics.org/manual/cairo-XLib-Surfaces.html ?

There must be a way

This library only prepares the image data in the form of an RGBA pixel array; what to do with it next is up to the programmer

I don't have a compiled *.so for Linux on hand, so I could try to check it out. Maybe there are examples of working with Cairo somewhere in LCL Lazarus, or in the examples that come with the distribution, or here on the forum. I think someone has already discussed it. I also saw Cairo being used in FPC/Lazarus on a German-language forum

This is one of its modes of operation, by the way. It can also use output to OpenGL and WebGPU
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #23 on: February 09, 2026, 11:46:26 am »
I might install Visual Studio and compile the dll on my AMD computer?

Unfortunately, in this case, I don't know what the problem could be...

If the problem could at least be reproduced on my end, I might be able to do something, but without local reproduction, I have no more ideas about what it could be.
Could @Roland57
help you? But I don't know
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #24 on: February 09, 2026, 11:51:46 am »
@Boleeman

Another idea - perhaps you simply don't have certain DLL dependencies, such as outdated (or, conversely, missing old versions) of the VCRedist runtime
I may seem rude - please don't take it personally

BildatBoffin

  • New Member
  • *
  • Posts: 47
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #25 on: February 09, 2026, 11:55:53 am »
Quote
This is one of its modes of operation, by the way. It can also use output to OpenGL and WebGPU

Yes, this is what is interesting compared to Cairo, Thor seems to have a faster backend.

Roland57

  • Hero Member
  • *****
  • Posts: 587
    • msegui.net
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #26 on: February 09, 2026, 06:31:11 pm »
Share the *.so file (I may not be able to use it due to some incompatibility with system libraries, but I'll give it a try)

Also, maybe this advice can help you?

I said how I compiled the library in my message. It is very easy.

After that, I renamed it this way (in Lazarus demo directory):

Code: Bash  [Select][+][-]
  1. cp ~/Documents/pascal/thorvg/builddir/src/libthorvg-1.so.1.0.0 libthorvg.so

Also, maybe this advice can help you?

I tried. It doesn't change the behaviour of the program.
My projects are on Codeberg.

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 404
  • I use FPC [main] 💪🐯💪
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #27 on: February 09, 2026, 07:30:21 pm »
The code now compiles without error using Lazarus 64Bit compiler on my AMD laptop and the exe runs successfully.
Hooray.
If I hadn't happened to flip through the pages, I wouldn't have noticed that you succeeded
Congratulations!
(If you had written a new message, I would have seen it in the RSS feed)
I may seem rude - please don't take it personally

Boleeman

  • Hero Member
  • *****
  • Posts: 1118
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #28 on: February 10, 2026, 09:34:56 am »
Here is the static linked thorvg-1.dll compiled by myself with all these loaders hopefully enabled: 'svg', 'png', 'jpg', 'lottie', 'ttf', 'webp' with ALLIGATOR's slightly modified source and a driving lottie example.

(Hooray I finally worked out how to compile some c++ code to a dll).


Many thanks to ALLIGATOR for his advice and Hermet Park (and The ThorVG Team).

*** Sorry about the previous mis-spelling Hermet  ***

Now Lazarus users will be able to add nice svg graphics and animations to their GUI's. Fantastic.


Roland57:
Did you get it working on Linux? Not sure if before you made the build you set the options?
I was getting those access errors in Windows for a while until I worked out the compile switches.
Also I am using Visual Studio 2026 to compile. Not sure what you used (MingW?)?
« Last Edit: February 11, 2026, 11:25:42 am by Boleeman »

hermet

  • Newbie
  • Posts: 3
Re: ThorVG - test (lightweight vector graphics engine)
« Reply #29 on: February 11, 2026, 09:05:11 am »
Here is the static linked thorvg-1.dll compiled by myself with all these loaders hopefully enabled: 'svg', 'png', 'jpg', 'lottie', 'ttf', 'webp' with ALLIGATOR's slightly modified source and a driving lottie example.

(Hooray I finally worked out how to compile some c++ code to a dll).


Many thanks to ALLIGATOR for his advice and Hermit Park (and The ThorVG Team).

(Not sure but Samsung looks like it is involved as well or maybe just end user, probably for their Android Apps?).


Now Lazarus users will be able to add nice svg graphics and animations to their GUI's. Fantastic.

PS: ALLIGATOR: I tried not to spam the thread, that's why I did not reply later on.

Roland57:
Did you get it working on Linux? Not sure if before you made the build you set the options?
I was getting those access errors in Windows for a while until I worked out the compile switches.
Also I am using Visual Studio 2026 to compile. Not sure what you used (MingW?)?

Cool!

PS. My name is Hermet, not Hermit. :)

 

TinyPortal © 2005-2018