[gtkada] Heap corruption and other problems

Dmitry A. Kazakov mailbox at dmitry-kazakov.de
Mon Aug 12 18:44:17 CEST 2013


On Mon, 12 Aug 2013 08:05:59 -0700, you wrote:

> I still have to 
> figure out how to get that tasking part working again as I liked how I 
> could do an Update call every so many milliseconds.

Glib.Main.Timeout_Add + Gtk.Widget.Queue_Draw from there. It should not be
tighter than 20ms, human eye cannot see any difference anyway. This is
exactly how the refresh engine from AICWL works. It is used for animated
widgets like the oscilloscope, clocks etc.

>>> Is your widget a descendant of Gtk_Drawing_Area_Record?
> No.  I still have not chosen to use Gtk in any form and all of my code, 
> and now my sample GTk3 code, still is GTK free.

I don't understand this. Your widget must be a descendant of at least
Gtk_Widget_Record.

>> As I said, there is something wrong with the way you handle it. You 
>> should simply catch "draw" and use the cairo context it comes with. 
>> You may also draw on other events, e.g. doing mouse tracking, by 
>> getting the context from the widget's window. Of course you should 
>> keep track of that internally and be prepared to repeat exactly same 
>> drawing from "draw". 
> Yes. I have in my example program changed the contents of window back 
> and forth between the circular text example and a box example that I 
> found on the net.  It is the box drawing that seems to have issues.

The oscilloscope works pretty smoothly and it does a lot more drawing than
filled rectangles. Filled rectangles are relatively efficient in Cairo. It
is lines which are rather slow.

It is also possible to prepare a memory-mapped image and transfer it as a
whole (as a pixbuf) into the Cairo context. The coming version of GtkAda
contributions will a package for this.

>> No, I used cairo from GtkAda 3.4. Prior to GtkAda 3.4 it was Damien's 
>> cairo bindings, which were higher level than ones from GtkAda. I 
>> ported AICWL to the GtkAda 3.4 Cairo.
> I'll be glad to see you next version of AICWL as you may already found 
> issues that I am not aware of in the conversion process.

I am waiting for other problems resolved and GtkAda packaged for Linux. I
can post code snippets from AICWL if you are interested.

>> Yes, I remember some operation, but they weren't actually needed in 
>> the end. What I did is a controlled Ada font type with cairo toy font 
>> and pango font back-ends. Because toy and pango font interfaces have 
>> nothing in common. 
> I had to add in bindings for:
> 
>    function Get_Default_Root_Window return Gdk_Window;

Gdk_Window is unusable, IMO.

>    procedure Update_Layout (Cr : Cairo.Cairo_Context; Layout : 
> Pango.Layout.Pango_Layout);
>    function Create_Layout (Cr : Cairo.Cairo_Context) return 
> Pango.Layout.Pango_Layout;
> 
> without the last two, I was not able to get the rotated "text" example 
> to work.

You should *first* do all transformations and only *then* use Show_Layout.
I know it sounds crazy, but this is how Cairo works. Keep in mind doing
Translate to the point around which you rotate the text and Move_To to the
point where you start drawing the text origin. If you stretch and skew the
text you should use Get_Extents before that and take into account gains
afterwards, which may become a linear combination of cosine and sine. This
is the way AICWL draws its texts.

I didn't use Update_Layout because I didn't figure from the documentation
what it did exactly and because I am using Cairo toy fonts in the same
code. The common denominator for both is get extents + show.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


More information about the gtkada mailing list