Murga-Projects Forums
segmentation fault while using fltk?? - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: segmentation fault while using fltk?? (/showthread.php?tid=336)


segmentation fault while using fltk?? - jyf1987 - 08-16-2008 03:54 AM

this is my test code to use fltk
the problem is when i add
fltk.fl_circle(110,100,50)

this will make a segmentation fault!
if remove this ,the script works well,so how to solve it?

ps:the problem both occur at win/lin
and other simple draw method will occur this too,


the code:[/code]

Code:
ww=220
wh=200

math.randomseed(os.time())

w=fltk:Fl_Window(ww,wh,"my fltk demo")
b=fltk:Fl_Box(2,2,218,198)
b:color(fltk.FL_WHITE)
b:box(fltk.FL_FLAT_BOX)



fltk.fl_circle(110,100,50)


w:show()
Fl:run()




RE: segmentation fault while using fltk?? - mikshaw - 08-16-2008 12:29 PM

all drawing functions require that you make_current the window on which you want to draw, and in some cases you may need to also set the font and color.

You should refer to the drawing examples provided with the murgaLua distibution, and you might need to play around a bit. If I recall correctly, most of the drawing things I've tried have also required the drawing functions to be put inside a function.


RE: segmentation fault while using fltk?? - jyf1987 - 08-16-2008 02:16 PM

but i want to draw things when the window load,so which function should i put inside the draw action?


RE: segmentation fault while using fltk?? - mikshaw - 08-16-2008 11:19 PM

I did this very thing not long ago, and it required some poking before I came up with something that worked. Eventually found it needed to be drawn before Fl:run for some reason, which required a flush and a check. I never quite understood exactly what was happening, but this was the only way it would draw when the window itself was drawn:

Code:
my_window:show()
Fl:flush() -- these two lines are necessary to draw before run() is called
Fl:check()
my_drawing_function()
Fl:run()


The code is shown in practice in the beta4 version of the murgaLua demos package (test-lcd_numbers.lua)
http://www.murga-projects.com/forum/attachment.php?aid=40


RE: segmentation fault while using fltk?? - jyf1987 - 08-17-2008 11:16 AM

it's true,thank u very much