Recent

Author Topic: Bindings for PlutoVG  (Read 4035 times)

CynicRus

  • Jr. Member
  • **
  • Posts: 55
Bindings for PlutoVG
« on: March 15, 2025, 07:09:50 pm »
Hello everyone! Today I made bindings for PlutoVG (PlutoVG is a standalone 2D vector graphics library in C.) (https://github.com/sammycage/plutovg) for Lazarus (Delphi 7 & 12 also supported). Can be found here: https://github.com/CynicRus/PlutoVG-bindings-for-Lazarus-Delphi


Boleeman

  • Hero Member
  • *****
  • Posts: 1002
Re: Bindings for PlutoVG
« Reply #1 on: August 16, 2025, 09:37:07 am »
Thanks CynicRus for the bindings for PlutoVG.

I accidentally came across your github PlutoVG page and decided to try it out.
Success with the 64Bit version (I just kept the same folder structure as in the zip file).

I don't know why but the 32 bit version in Windows 10/ Lazarus 2.2.4 comes up with an access violation.

Not sure if you can possibly help with that 32 Bit version?




« Last Edit: August 16, 2025, 10:07:08 am by Boleeman »

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Bindings for PlutoVG
« Reply #2 on: August 16, 2025, 10:45:35 am »
Make sure the calling conventions are correct.
In this case probably  cdecl for 32 bit.
You don't need to add cdecl for every routine if you just add {$if defined(CPU32)}{$CALLING cdecl}{$ifend} at the top of the bindings
I would also add {$Packrecords C}
There is a slight chance it is {$CALLING stdcall}, but I think it is  cdecl
« Last Edit: August 16, 2025, 12:15:38 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: Bindings for PlutoVG
« Reply #3 on: August 16, 2025, 03:22:50 pm »
Maybe the 32-bit DLL isn't being picked up, could a different name for it be a better idea so that when the path name is chosen the compiler can look at the correct one?

 I looked at the C sources, why can't a set of Units/Package be made instead of using DLLs? I really don't like that idea unless I myself compile it.

  That maybe a good exercise for a C converter I partially have working.


 Jamie

The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Bindings for PlutoVG
« Reply #4 on: August 16, 2025, 03:53:06 pm »
No Jamie, it is the missing calling convention (I agree about the dll, though).
To get it working for 32 bit windows, the calling convention needs to be specified.
64 bit is less picky.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Boleeman

  • Hero Member
  • *****
  • Posts: 1002
Re: Bindings for PlutoVG
« Reply #5 on: August 17, 2025, 06:43:47 am »
Ah, I tried adding these at the top of the bindings in unit plutovg_api;
{$if defined(CPU32)}{$CALLING cdecl}{$ifend}
{$Packrecords C}

like this:

unit plutovg_api;

interface
{$if defined(CPU32)}{$CALLING cdecl}{$ifend}
{$Packrecords C}


{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}


but I still get that error.

Looks like it is using cdecl; external PLUTOVG_LIB;

I am running Win 10 64 bit CPU, but compiling with 32 bit Lazarus 2.2.4 FPC 3.2.2  i386-win32

With the 64Bit version, I needed to keep the folder structure for it to work.

I tried the same folder structure for 32 Bit compilation (and the added switches) but still cannot get rid of the error.

Access violation at Address 64D15631    ($3F80000C)  

64D15631 D9400C                   fld dword ptr [eax+$0C]
64D15634 D905A4C2D364             fld dword ptr [$64D3C2A4]
64D1563A DEC9                     fmullp st(1),st(0)
64D1563C D91C24                   fstp dword ptr [esp]
64D1563F E8EC290200               call +$000229EC
64D15644 8945F4                   mov [ebp-$0C],eax
64D15647 8B4508                   mov eax,[ebp+$08]
64D1564A D900                     fld dword ptr [eax]
64D1564C D905A4C2D364             fld dword ptr [$64D3C2A4]
64D15652 DEC9                     fmullp st(1),st(0)
64D15654 D91C24                   fstp dword ptr [esp]
64D15657 E8D4290200               call +$000229D4
64D1565C 8945F0                   mov [ebp-$10],eax
64D1565F 8B4508                   mov eax,[ebp+$08]
64D15662 D94004                   fld dword ptr [eax+$04]


fld dword ptr [eax+$0C]) is the FPU trying to load a Single from an invalid pointer.
Assigning @PLUTOVG_IDENTITY_MATRIX to a variable of the wrong type (record vs pointer)
or
passing an uninitialized/incorrect pointer possibly causes the problem?


Currently have in unit plutovg_api;:

  // 2D Transformation Matrix
  plutovg_matrix_t = ^plutovg_matrix;
  plutovg_matrix = record
    a: single;
    b: single;
    c: single;
    d: single;
    e: single;
    f: single;
  end;   
« Last Edit: August 17, 2025, 06:46:42 am by Boleeman »

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: Bindings for PlutoVG
« Reply #6 on: August 17, 2025, 11:59:51 am »
 Iether the translation was incorrect and should have been double instead of single floats or you may have to set the mask of the exception for floating Point errors in your program to have it avoid the fault
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: Bindings for PlutoVG
« Reply #7 on: August 17, 2025, 12:27:48 pm »
Have you tried running your program outside of the debugger
The only true wisdom is knowing you know nothing

Boleeman

  • Hero Member
  • *****
  • Posts: 1002
Re: Bindings for PlutoVG
« Reply #8 on: August 19, 2025, 04:54:49 pm »
I tried using Double instead of single floats.  Failed to fix problem

I tried running your program outside of the debugger.    Failed to fix problem


How do you set the mask of the exception for floating Point errors?


Not sure if Tomxe could possibly help out to fix the fault?

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Bindings for PlutoVG
« Reply #9 on: August 19, 2025, 05:44:01 pm »
 SetExceptionMask(GetExceptionMask + [exOverflow,exZeroDivide,exInvalidOp]); // from the wiki.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Boleeman

  • Hero Member
  • *****
  • Posts: 1002
Re: Bindings for PlutoVG
« Reply #10 on: August 22, 2025, 09:27:34 am »
OK I tried that:  SetExceptionMask(GetExceptionMask + [exOverflow,exZeroDivide,exInvalidOp]);

But still get that error for 32Bit dll version

Also tried:
SetExceptionMask(GetExceptionMask + [exInvalidOp,exDenormalized,exZeroDivide,exOverflow,exUnderflow,exPrecision]);

Boleeman

  • Hero Member
  • *****
  • Posts: 1002
Re: Bindings for PlutoVG
« Reply #11 on: August 22, 2025, 12:26:04 pm »
Yay finally got the 32Bit working without error.

In unit plutovg_api;  I needed to replace some bits with the red versions:

//procedure plutovg_surface_clear(surface: plutovg_surface_t;
  const color: plutovg_color_t); cdecl; external PLUTOVG_LIB;

with:

procedure plutovg_surface_clear(surface: plutovg_surface_t;
  const color: pplutovg_color_t); cdecl; external PLUTOVG_LIB;


and in the Main form:

    {$IFDEF WINDOWS}
    plutovg_surface_clear(Surface, @PLUTOVG_WHITE_COLOR);
 

Another minor fix was for the version:

function plutovg_version: LongInt; cdecl; external PLUTOVG_LIB;
« Last Edit: August 22, 2025, 01:01:52 pm by Boleeman »

CynicRus

  • Jr. Member
  • **
  • Posts: 55
Re: Bindings for PlutoVG
« Reply #12 on: November 11, 2025, 04:49:28 pm »
Thanks! Sorry, I haven't visited the forum for a long time. I'll fix it in the repository soon. I'll respond more quickly on GitHub Issues.

 

TinyPortal © 2005-2018