Recent

Author Topic: Strange error at use GTK  (Read 3757 times)

yyttyy

  • New Member
  • *
  • Posts: 18
Strange error at use GTK
« on: October 25, 2020, 07:10:39 pm »
At use procedure gdk_pixbuf_render_pixmap_and_mask with parametrs: (Pixbuf, @Background, nil, 0) the terminal returns an error: OutputWindow.pp(37,64) Error: Can't assign values to an address.
64 symbol it is fourth parametr, which expects longint value. What the problem?.
Code: Pascal  [Select][+][-]
  1. unit OutputWindow;
  2. interface
  3.  
  4. procedure CreateWindow();
  5.  
  6. implementation
  7.  
  8. uses glib2, gdk2pixbuf, gdk2, gtk2;
  9.  
  10. procedure BackgroundInit(var Pixbuf : PGdkPixbuf);
  11. var
  12.     PathToBackG : array [0..100] of char;
  13.     error : PGError;
  14. begin
  15.     PathToBackG := '/home/yarik/Desktop/Zhuzhculator/GUIZhuzh/Background.bmp';
  16.     error := nil;
  17.     Pixbuf :=  gdk_pixbuf_new_from_file(@PathToBackG , @error);
  18.     if error <> nil then
  19.     begin
  20.         if error^.domain = GDK_PIXBUF_ERROR then
  21.         begin
  22.             g_print('Pixbuf Related Error'#10);
  23.             halt(1)
  24.         end;
  25.         if error^.domain = G_FILE_ERROR then
  26.         begin
  27.             g_print('File Error: Check file permissions and state'#10);
  28.             halt(1)
  29.         end;
  30.     end;
  31. end;
  32.  
  33. procedure SetStyle(var Style : PGtkStyle; Pixbuf : PGdkPixbuf);
  34. var
  35.    Background : PGdkPixmap;
  36. begin
  37.     gdk_pixbuf_render_pixmap_and_mask (Pixbuf, @Background, nil, 0);
  38.     Style := gtk_style_new();
  39.     Style^.bg_pixmap[0] := Background;
  40. end;
  41.  
  42. procedure destroy (widget : pGtkWidget ; data : pgpointer); cdecl ;
  43. begin
  44. gtk_main_quit()
  45. end;
  46.  
  47. procedure CreateWindow();
  48. var
  49.     Window : PGtkWidget;
  50.     Background : PGtkWidget;
  51.     Style : PGtkStyle;
  52.     Pixbuf : PGdkPixbuf;
  53. begin
  54.     gtk_init(@argc, @argv);
  55.     Window := gtk_window_new(GTK_WINDOW_TOPLEVEL);
  56.     gtk_window_set_title(GTK_WINDOW(Window), 'Zhuzhculator');
  57.     gtk_widget_set_size_request(Window, 225, 425);
  58.     gtk_window_set_default_size(GTK_WINDOW(Window), 225, 425);
  59.     BackgroundInit(Pixbuf);
  60.     SetStyle(Style, Pixbuf);
  61.     gtk_widget_set_style(Window, GTK_STYLE(Style));
  62.     gtk_container_set_border_width(GTK_CONTAINER(Window), 0);
  63.     gtk_widget_show(Window);
  64.     gtk_signal_connect(PGtkObject(Window), 'destroy',
  65.                        GTK_SIGNAL_FUNC (@destroy), NULL);
  66.     gtk_main();
  67. end;
  68. end.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Strange error at use GTK
« Reply #1 on: October 25, 2020, 07:30:47 pm »
Code: Pascal  [Select][+][-]
  1. procedure SetStyle(var Style : PGtkStyle; Pixbuf : PGdkPixbuf);
  2. var
  3.    Background: PGdkPixmap;
  4.    maskReturn: PGdkPixmap = Nil;
  5. begin
  6.     gdk_pixbuf_render_pixmap_and_mask (Pixbuf, Background, maskReturn, 0);
  7.     Style := gtk_style_new();
  8.     Style^.bg_pixmap[0] := Background;
  9. end;

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: Strange error at use GTK
« Reply #2 on: October 25, 2020, 07:35:29 pm »
looks like the translation of the gdk_pixbuf_render_pixmap_and_mask header is incorrect. pixmap_return and mask_return parameters are declared as var but according to the documentation they can be nil.
https://developer.gnome.org/gdk2/stable/gdk2-Pixbufs.html#gdk-pixbuf-render-pixmap-and-mask
Currently, you must use a variable instead of a pointer to a variable. So the mask_return parameter must be a variable.
You should file a bug.
http://bugs.freepascal.org/

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: Strange error at use GTK
« Reply #3 on: October 25, 2020, 07:40:24 pm »
Code: Pascal  [Select][+][-]
  1. procedure SetStyle(var Style : PGtkStyle; Pixbuf : PGdkPixbuf);
  2. var
  3.    Background: PGdkPixmap;
  4.    maskReturn: PGdkPixmap = Nil;
  5. begin
  6.     gdk_pixbuf_render_pixmap_and_mask (Pixbuf, Background, maskReturn, 0);
  7.     Style := gtk_style_new();
  8.     Style^.bg_pixmap[0] := Background;
  9. end;
Unfortunately, this is not the case. The code you entered will create and return mask data as well.

yyttyy

  • New Member
  • *
  • Posts: 18
Re: Strange error at use GTK
« Reply #4 on: October 25, 2020, 08:10:20 pm »
lol, I thought the error was in parameter 4. So I try your variant and its doesn't work. Same error.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Strange error at use GTK
« Reply #5 on: October 25, 2020, 08:22:40 pm »
Strange, your code, with my minor alteration, displays a correctly rendered window here (using another bitmap than you specified, of course).
The documentation for which you provide a link says:
Quote
Parameters
pixbufA pixbuf.
pixmap_returnLocation to store a pointer to the created pixmap, or NULL if the pixmap is not needed.
mask_returnLocation to store a pointer to the created mask, or NULL if the mask is not needed.
which I take to mean that if you pass a Nil pointer in the mask_return pointer parameter, the unneeded mask is not created (or is discarded).

yyttyy

  • New Member
  • *
  • Posts: 18
Re: Strange error at use GTK
« Reply #6 on: October 25, 2020, 08:27:50 pm »
Can you give me your code please?

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: Strange error at use GTK
« Reply #7 on: October 25, 2020, 08:28:05 pm »
lol, I thought the error was in parameter 4. So I try your variant and its doesn't work. Same error.
Did you remove '@' in front of the variables?

Strange, your code, with my minor alteration, displays a correctly rendered window here (using another bitmap than you specified, of course).
The documentation for which you provide a link says:
Quote
Parameters
pixbufA pixbuf.
pixmap_returnLocation to store a pointer to the created pixmap, or NULL if the pixmap is not needed.
mask_returnLocation to store a pointer to the created mask, or NULL if the mask is not needed.
which I take to mean that if you pass a Nil pointer in the mask_return pointer parameter, the unneeded mask is not created (or is discarded).
Currently, nil cannot be specified because a variable is required so mask will be generated even if variable has nil value.

yyttyy

  • New Member
  • *
  • Posts: 18
Re: Strange error at use GTK
« Reply #8 on: October 25, 2020, 08:33:56 pm »
Year, i delete '@', and i tried more other variants.

yyttyy

  • New Member
  • *
  • Posts: 18
Re: Strange error at use GTK
« Reply #9 on: October 25, 2020, 08:36:53 pm »
I noticed that if I put '@' terminal refers to 72 symbol if I don't put it on 59.

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: Strange error at use GTK
« Reply #10 on: October 25, 2020, 08:41:38 pm »
I see you still have @ in front of Background variable. Remove both.

yyttyy

  • New Member
  • *
  • Posts: 18
Re: Strange error at use GTK
« Reply #11 on: October 25, 2020, 08:48:12 pm »
Oh my god, thank you for your help. I am new and for me it is very strange problem solution.

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: Strange error at use GTK
« Reply #12 on: October 25, 2020, 08:58:15 pm »
Best of all, your original code was correct from the point of view of gdk headers. Unfortunately, pascal interface is incorrectly translated. You found a bug.

It now looks like this:
procedure gdk_pixbuf_render_pixmap_and_mask(pixbuf:PGdkPixbuf; var pixmap_return:PGdkPixmap; var mask_return:PGdkBitmap; alpha_threshold:longint);

But it should look like this:
procedure gdk_pixbuf_render_pixmap_and_mask(pixbuf:PGdkPixbuf; pixmap_return:PPGdkPixmap;  mask_return:PPGdkBitmap; alpha_threshold:longint);

Then your original code would run correctly.
Please file a bug.
http://bugs.freepascal.org/

yyttyy

  • New Member
  • *
  • Posts: 18
Re: Strange error at use GTK
« Reply #13 on: October 25, 2020, 09:34:32 pm »
Ok!

 

TinyPortal © 2005-2018