Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wx-c with threads under linux... 'nuff said
#1
um... this works fine under windows, segfaults pretty quick under linux. :x any ideas? :normal:
Code:
'$include: "wx-c/wx.bi"
#define wxCLOSE_BOX &h1000
#define FALSE 0
#define TRUE NOT(FALSE)
declare function fixstring(a as string) as string
declare sub updatedaemon(byval poos as integer)
declare sub buttonClick(byval event as long,byval iListener as long)

dim shared wx_app as wxapp ptr,wxfr as wxframe ptr,test as wxbutton ptr,thingy as integer=2
dim shared wxWindowIsShown as integer=TRUE,threads(100) as integer

function fixstring(a as string) as string
  
   dim b as byte ptr
   b=sadd(a)
   fixstring = *b
  
end function

sub ButtonClick(byval event as long, byval iListener as long)
   if thingy<26 then
      threads(thingy)=threadcreate( @updatedaemon, thingy )
      thingy+=1
   end if
end sub

sub onclose(byval event as wxEvent ptr,byval iListener as long)
   wxWindowIsShown=FALSE
   for i=1 to thingy-1
      threadwait(threads(i))
   next
   wxEvent_Skip(event,TRUE)
end sub

sub App_OnInit ()

    wxfr = wxFrame ()
    wxFrame_Create (wxfr, 0, 1, "Welcome to WX-C", wxSize ( -1, -1), wxSize ( -1, -1), wxDEFAULT_FRAME_STYLE or wxCLOSE_BOX, "frame" )
    wxWindow_SetAutoLayout(wxfr,TRUE)
    test=wxbutton()
    wxButton_Create(test,wxfr,2,"Load a file!",wxSize(-1,-1),wxSize(-1,-1),0,0,0)
    wxEvtHandler_proxy( test, @ButtonClick )
    wxEvtHandler_connect(test,wxEvent_EVT_COMMAND_BUTTON_CLICKED(),2,-1,0)
    wxEvtHandler_proxy( wxfr, @onclose )
    wxEvtHandler_connect(wxfr,wxEvent_EVT_CLOSE_WINDOW(),1,-1,0)
    wxWindow_CenterOnScreen(wxfr,wxBOTH)
    wxWindow_Show ( wxfr, 1)
    threads(1)=threadcreate( @updatedaemon, 1 )
    wxApp_OnInit(wx_app)

end sub

sub updatedaemon(byval poos as integer)
   do
      i+=1
      locate poos,1: print i;
      wxButton_SetLabel(test,str$(i))
      sleep 10
   loop while wxWindowIsShown=TRUE
   print
end sub


sub App_OnExit()

    ' here your code executed on exit
    dim wx_msgbox_size as wxSize ptr= wxSize ( 150, 50)
    wxMsgBox ( 0, "Bye Bye...", "Window Closed!", 0, wx_msgbox_size)
    end

end sub

' main code...

  wx_app = wxApp()
  wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit)
  wxApp_Run(0,0)

end

[edit] ok guess it only works sometimes under windows too... :oops:
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#2
XP is good at hiding such things from you...
Reply
#3
yeah... strangely enough this one works all the time for me...
Code:
'$include: "wx-c/wx.bi"
#define wxCLOSE_BOX &h1000
#define FALSE 0
#define TRUE NOT(FALSE)
declare function fixstring(a as string) as string
declare sub updatedaemon(byval poos as integer)
declare sub buttonClick(byval event as long,byval iListener as long)

dim shared wx_app as wxapp ptr,wxfr as wxframe ptr,test as wxbutton ptr,thingy as integer=2
dim shared wxWindowIsShown as integer=TRUE,threads(100) as integer

function fixstring(a as string) as string
  
   dim b as byte ptr
   b=sadd(a)
   fixstring = *b
  
end function

sub ButtonClick(byval event as long, byval iListener as long)
   if thingy<26 then
      threads(thingy)=threadcreate( @updatedaemon, thingy )
      thingy+=1
   end if
end sub

sub onclose(byval event as long,byval iListener as long)
   wxWindowIsShown=FALSE
   for i=1 to thingy-1
      threadwait(threads(i))
   next
   wxEvent_Skip(event,TRUE)
end sub

sub App_OnInit ()

    wxfr = wxFrame ()
    wxFrame_Create (wxfr, 0, 1, "Welcome to WX-C", wxSize ( -1, -1), wxSize ( -1, -1), wxDEFAULT_FRAME_STYLE or wxCLOSE_BOX, "frame" )
    wxWindow_SetAutoLayout(wxfr,TRUE)
    test=wxbutton()
    wxButton_Create(test,wxfr,2,"Load a file!",wxSize(-1,-1),wxSize(-1,-1),0,0,0)
    wxEvtHandler_proxy( test, @ButtonClick )
    wxEvtHandler_connect(test,wxEvent_EVT_COMMAND_BUTTON_CLICKED(),2,-1,0)
    wxEvtHandler_proxy( wxfr, @onclose )
    wxEvtHandler_connect(wxfr,wxEvent_EVT_CLOSE_WINDOW(),1,-1,0)
    wxWindow_CenterOnScreen(wxfr,wxBOTH)
    wxWindow_Show ( wxfr, 1)
    threads(1)=threadcreate( @updatedaemon, 1 )
    wxApp_OnInit(wx_app)

end sub

sub updatedaemon(byval poos as integer)
   do
      i+=1
      locate poos,1:? i
      wxButton_SetLabel(test,str$(i))
      sleep 10
   loop while wxWindowIsShown=TRUE
   sleep poos*10
   ? "thread ";poos;" exited."
end sub

sub App_OnExit()

    ' here your code executed on exit
    dim wx_msgbox_size as wxSize ptr= wxSize ( 150, 50)
    wxMsgBox ( 0, "Bye Bye...", "Window Closed!", 0, wx_msgbox_size)
    end

end sub

' main code...

  wx_app = wxApp()
  wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit)
  wxApp_Run(0,0)

end
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)