|
From: Kent D. <ke...@st...> - 2001-11-26 21:52:19
|
Hi.
As I'm trying to implement the "Simple Text Editor" sample in Ruby-Fltk,
(or should that be Ruby-FLTK now? ;-) I found out that the Fl::paste
wasn't wrapped.
So I gave it a naive try, which works, but seg-faults if Fltk.paste(
widget ) is called outside when Fltk.run is running...
I'm guessing that this is due to something in FLTK, and I wonder if
there is any to check to see that the Fltk.run is running? (See below
about Fl::check and Fl::ready)
<CVSDIFF>
[kentda@v128a ruby-fltk]$ cvs diff
? test/fl_func.rb
cvs server: Diffing .
Index: fltk.cc
===================================================================
RCS file: /cvsroot/ruby-fltk/ruby-fltk/fltk.cc,v
retrieving revision 1.65
diff -r1.65 fltk.cc
849a850,865
> /**
> * the Fl::paste(Fl_Widget*) method
> */
> static VALUE rb_fltk_paste( VALUE self, VALUE widget ){
> Fl_Widget *reciever = NULL;
> reciever = rb_to_fl(widget);
> if(reciever) {
> Fl::paste( *reciever );
> }else{
> rb_raise(rb_eArgError, "Need widget to send paste-event to.");
> }
> return Qnil;
> }
>
>
>
972a989
> DEF_MODULE_FUNC(paste,1);
</CVSDIFF>
Some testcode
<CODE>
require 'rubyfltk.so'
w = Fltk::Window.new(0,0,200,200)
b = Fltk::Button.new(0,0,20,20,"X"){|a,b|
Fltk.paste(w)
}
w.show
#Fltk.paste( b) # this crashes
Fltk.run # here, pushing the button which calls Fltk.paste(w) goes ok.
#Fltk.paste( b ) # this crashes too.
</CODE>
After writing the above, I did try using Fl::check(), but I'm not sure
that is a safe bet, since the Fl::ready() documentation talks about
callbacks maybe being illegal, and Fl::ready() returns values that don't
seem to mean quite the same.
The seg-faults disappear if I add this test to the rb_fltk_paste
implementation before Fl::paste...
<CODE>
if(!Fl::check())
rb_raise(rb_eSystemCallError, "FLTK does not appear to be taking
events!");
</CODE>
I hope my code isn't totally embarrasing :-)
--
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
)____(stud.techn.;ind.øk.data)||(softwareDeveloper.at(Trustix))_(
/"Opinions expressed are mine and not those of my Employer, "\
( "the University, my girlfriend, stray cats, banana fruitflies, " )
\"nor the frontal lobe of my left cerebral hemisphere. "/
|