Strange IMA - help appreciated

Linux specific forum
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Strange IMA - help appreciated

Post by WishMaster »

Code: Select all

Declare Eins()
Declare Zwei()
Declare Event_Handler()

Procedure Eins()
    OpenWindow(1, 0, 0, 100, 100, "Hallo")
    CreateGadgetList(WindowID(1))
    ButtonGadget(1, 0, 0, 100, 100, "Zwei!")
    
    Repeat
    
    Until Event_Handler() = #PB_Event_CloseWindow
EndProcedure

Procedure Zwei()
    OpenWindow(2, 0, 0, 100, 100, "Hallo 2")
    CreateGadgetList(WindowID(2))
    EditorGadget(2, 0, 0, 100, 100)
    gtk_text_buffer_create_tag_(gtk_text_view_get_buffer_(GadgetID(2)), "bold", "weight", 800)
    
    Repeat
    
    Until Event_Handler() = #PB_Event_CloseWindow
EndProcedure

Procedure Event_Handler()
    Event = WaitWindowEvent(20)
    Select Event
    Case #PB_Event_Gadget
        Select EventGadget()
            Case 1
                Zwei()
        EndSelect
    Default
        ProcedureReturn Event_Handler
    EndSelect
EndProcedure

Eins()
Why does this give an Invalid Memory Access?


//Edit:
This one works fine:

Code: Select all

Declare Eins() 
 Declare Zwei() 
 Declare Drei()
 Declare Event_Handler() 
 
 Procedure Eins() 
     OpenWindow(1, 0, 0, 100, 100, "Hallo") 
     CreateGadgetList(WindowID(1)) 
     ButtonGadget(1, 0, 0, 100, 100, "Zwei!") 
     
     Repeat 
     
     Until Event_Handler() = #PB_Event_CloseWindow 
 EndProcedure 
 
 Procedure Zwei() 
     OpenWindow(2, 0, 0, 100, 100, "Hallo 2") 
     CreateGadgetList(WindowID(2)) 
     EditorGadget(2, 0, 0, 100, 100) 
     Drei()
     
     Repeat 
     
     Until Event_Handler() = #PB_Event_CloseWindow 
 EndProcedure
 
 Procedure Drei()
 gtk_text_buffer_create_tag_(gtk_text_view_get_buffer_(GadgetID(2)), "bold", "weight", 800) 
 EndProcedure
 
 Procedure Event_Handler() 
     Event = WaitWindowEvent(20) 
     Select Event 
     Case #PB_Event_Gadget 
         Select EventGadget() 
             Case 1 
                 Zwei() 
         EndSelect 
     Default 
         ProcedureReturn Event_Handler 
     EndSelect 
 EndProcedure 
 
 Eins()
Image Image
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

You don't like me 'cause I've red hair, do you?
Image Image
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

:D :D do you have?... no, that's not the reason...
I'd changed the code a little to get an output on the console... (switch to console in compiler options)

Code: Select all

Declare Eins()
Declare Zwei()
Declare Event_Handler()

Procedure Eins()
    OpenWindow(1, 0, 0, 100, 100, "Hallo")
    CreateGadgetList(WindowID(1))
    ButtonGadget(1, 0, 0, 100, 100, "Zwei!")
   
;     Repeat
   
;     Until
;      Event_Handler(); = #PB_Event_CloseWindow
EndProcedure

Procedure Zwei()
    OpenWindow(2, 0, 0, 100, 100, "Hallo 2")
    CreateGadgetList(WindowID(2))
    EditorGadget(2, 0, 0, 100, 100)
    
    gtk_text_buffer_create_tag_(gtk_text_view_get_buffer_(GadgetID(2)), "bold", "weight", 800)
   
;     Repeat
   
;     Until 
;     Event_Handler() ;= #PB_Event_CloseWindow
EndProcedure


Eins()
Repeat
    Event = WaitWindowEvent(20)
    Select Event
    Case #PB_Event_Gadget
    If EventType()=#PB_EventType_LeftClick
        Select EventGadget()
            Case 1
                Zwei()
        EndSelect
    EndIf
    Default
;         ProcedureReturn Event_Handler
    EndSelect
 Until Event=#PB_Event_CloseWindow
if you now press the button, the putput on the console is like:

Code: Select all


(purebasic.exe:9355): GLib-GObject-WARNING **: IA__g_object_set_valist: object class `GtkTextTag' has no property named `h%'
I guess there is a bug somewhere around Glib.... may Fred could check this...

But why this leads to an ivalid memory access... :cry:
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

gtk_text_buffer_create_tag () is a function with variable arguments.
PB does not support C-style variable arguments.
Basically you are not terminating your property list with a NULL, which leads to the crash.

You will have to call gtk_text_tag_new() to create the tag, then set the properties and add it to the buffer yourself.
quidquid Latine dictum sit altum videtur
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

You have to use g_object_set() to change the properties of a tag created by gtk_text_tag_new()....
And g_object_set() also has these veriable arguments...
Image Image
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Use g_object_set_property then.
gtk has a non C-specific solution for all the features, as it is intended to be used by other languages as well.
quidquid Latine dictum sit altum videtur
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

What's wrong here - it gives an IMA:

Code: Select all

OpenWindow(2, 0, 0, 100, 100, "Hallo 2") 
CreateGadgetList(WindowID(2)) 
EditorGadget(2, 0, 0, 100, 100) 

buffer = gtk_text_view_get_buffer_(GadgetID(2))
tag = gtk_text_tag_new_("mytag")
g_object_set_property_(tag, "weight", 800)
gtk_text_tag_table_add_(buffer, tag)

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 
Image Image
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

*bump*
Image Image
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

WishMaster wrote:*bump*
... and your point is ?

I could come up with a working example for you, but i really do not see why
i should do your work, especially if all i get is these annoying bumps.

Your problem is that you do not read the gtk manual carefully. You cannot simply
put up some not working code and expect others to do the work for you.

g_object_set_property() expects a GValue, not an integer as you pass to it. Of course this crashes.

Now, to get a GValue of type int, you need g_value_init() and g_value_set_int()
http://developer.gnome.org/doc/API/2.0/ ... tml#GValue
http://developer.gnome.org/doc/API/2.0/ ... #id2612224

Now i suggest you read that documentation and do some coding yourself.

Alternatively, you could try to load the gtk libs with OpenLibrary and call
the C varargs functions directly.
But if you're not looking at the documentation, your chances with that are low as well...
quidquid Latine dictum sit altum videtur
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

Hey, it would have been a single line of code and eventually another line for a small explanation.

Reading the GTK docs - that's what I do all the time.
The GTK terms for variable types always differ from the PB ones - so it's IMO not a crime to take GValue for an ordinary PB long.

Doing coding on my own - that's also something I spend quite much time for but sometimes I have - just like everybody else - a more or less tricky problem to solve - so I post my question in the board.

As you are unfortunately the only one in the PB community with some GTK knowledge it's quite natural to post here.
I excuse if this board isn't meant to ask questions.
Image Image
Post Reply