Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault with cairo transform and matrix #222

Open
m4z-0xf00 opened this issue May 6, 2023 · 5 comments
Open

segfault with cairo transform and matrix #222

m4z-0xf00 opened this issue May 6, 2023 · 5 comments

Comments

@m4z-0xf00
Copy link

m4z-0xf00 commented May 6, 2023

Hello, I am trying to use cairo tranform with this code, but I get a segfault, it looks like matrixIinit doesn't initialize the matrix or that transform doesn't understand it

  var mtx: cairo.Matrix
  matrixInit(mtx, 1.0, 0.0, 0.5, 1.0, 0.0, 0.0)
  ctx.transform(mtx)

I tried to understand the declarations in cairo.nim but I dont really get it
the doc tells this:

typedef struct {
    double xx; double yx;
    double xy; double yy;
    double x0; double y0;
} cairo_matrix_t;

and cairo.nim

type
  Matrix00* {.pure.} = object
  Matrix* = ref object of RootRef
    impl*: ptr Matrix00
    ignoreFinalizer*: bool

I wonder if matrixInit should call cairo_matrix_init with Matrix.impl instead

proc matrixInit*(matrix: var Matrix; xx, yx, xy, yy, x0, y0: float) =
  cairo_matrix_init(matrix, xx.cdouble, yx.cdouble, xy.cdouble, yy.cdouble, x0.cdouble, y0.cdouble)
@StefanSalewski
Copy link
Owner

Thanks for reporting. Please excuse the late response, I had some trouble with my PC monitor, the old one suddenly dyed, so I had to order a new one. The new one is a 32-inch 4k, really nice. Have some other work still, including fixing a few remaining issues in the Nim book, but will try to investigate your concern soon.

@m4z-0xf00
Copy link
Author

m4z-0xf00 commented May 13, 2023

Hey, don't worry I don't mind at all, we all have lives and you don't owe me anything. The transform was for shearing operation and it can be easily done with other ways so I can live without that at the moment. 32 inch screen must be awesome, you'll need a tiling wm with that or you'll end up losing windows ^^ Hope you'll have fun!

@StefanSalewski
Copy link
Owner

Hello. Your observation is correct, the gintro Cairo matrix definition is very wrong. It should be a plain stack entity like cairo Rectangle and IntRectangle. Unfortunately, it is nearly impossible to detect automatically, which entities are stack allocated, and which are library created and have a proxy object in gintro. GtkTextIter is another example of such a stack entity, but we have a few more, in the generator script gen.nim is a list. So my initial idea was to just add cairo.Matrix to that list and be done. But surprisingly, in the GIR file the fields of that cairo matrix are not defined. That is strange, IntRectangle for example has fields. So the only solution is to define the Matrix type manual. Not difficult, but then we should test if it works.

So my question: Do you really intend to use Cairo with gintro? I ask, because my impression is, that we have currently very very few gintro users. GTK has generally few users. And for cairo, the alternatives may be Pixie of Mr. treeform. Or Blend2d, for which we currently have no Nim bindings. And there are rumors that they try hard to break gintro for upcomming v2.0.

I am currently not using Nim anymore. I try from time to time, but the fun and motivation is just gone. There have been a few insulting posts in Nim forum like https://forum.nim-lang.org/t/10101#66729 -- from Rumpf himself and his moderator fanboys. Nim is not a bad language, but when the fun is gone, it is just hard to continue using it. At least when no one pays for the work. I try to fix the remaining typos in the book, but even finding motivation for that is hard. Maybe I will try in next winter, or in a few years again some Nim? But well, there are enough other languages.

So when you really should intend to use cairo with gintro, I can ship a patch tomorrow, but you would have to test it yourself. I will ask in Gnome forum why the GIR matrix has no fields. But whatever the answer is, it is very easy to fix manually.

@StefanSalewski
Copy link
Owner

After the reply from Mr. Bassi, I have just pushed the fix.

Cairo Matrix is now manually defined in cairoimpl.nim, and I patched gen.nim to skip the Matrix type. My feeling is, that the other procs in cairoimpl.nim are not affected by this change. But actually, I have no test code available for testing. I hope that this fix will not break gintro for other people, I don't think so, as the fix is tiny.

Note that there are rumors that gintro will not install with latest Nim devil compiler! But v1.6.12 should work, I used that version myself some months ago.

@StefanSalewski
Copy link
Owner

And of course head install with

nimble uninstall gintro
nimble install gintro@#head

as we do not create releases any more, due to the 0.9.9 version number and for some other reasons as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants