Threads running on OS X 10.9
Threads running on OS X 10.9
Anyone else having issues with threads crashing on OS X 10.9? I can run the same code all day long on OS X 10.6.8. I made sure "App Nap" wasn't the issue by selecting "Prevent App Nap" but it still crashes. I'll have to write a smaller code example and see if I get the same issue. If so, I'll post it.
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: Threads running on OS X 10.9
Ok, here's the code to test. It runs just fine on OS X 10.6.8. On OS X 10.9.3 (Developer Release) it has the following issues...
- EditorGadget() doesn't retain focus until it has been running for about 20 seconds or so. You have to keep clicking your mouse on the EditorGadget() to refresh it.
- The EditorGadget() never shows a scroll bar.
- The thread pretty much quits working after 49 seconds.
Code: Select all
Procedure Run(Parameter)
StartTime = ElapsedMilliseconds()
Repeat
If ElapsedMilliseconds() - StartTime >= 1000
StartTime = ElapsedMilliseconds()
AddGadgetItem(0, CountGadgetItems(0), Str(ElapsedMilliseconds() / 1000))
PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_Change)
EndIf
Delay(1)
ForEver
EndProcedure
If OpenWindow(0, 0, 0, 420, 270, "Thread Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 400, 250)
CreateThread(@Run(), Parameter)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change
Range.NSRange\location = Len(GetGadgetText(0))
CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @Range)
EndIf
EndSelect
EndSelect
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIfwww.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: Threads running on OS X 10.9
It looks like the problem is caused by adding the gadget items in another thread.
Try to add them in the main thread.
In your example code AddWindowTimer(#Window, Timer, Timeout) can also be used.
Try to add them in the main thread.
In your example code AddWindowTimer(#Window, Timer, Timeout) can also be used.
Code: Select all
Procedure Run(Parameter)
StartTime = ElapsedMilliseconds()
Repeat
If ElapsedMilliseconds() - StartTime >= 1000
StartTime = ElapsedMilliseconds()
PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_Change)
EndIf
Delay(1)
ForEver
EndProcedure
If OpenWindow(0, 0, 0, 420, 270, "Thread Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 400, 250)
CreateThread(@Run(), Parameter)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change
AddGadgetItem(0, -1, Str(ElapsedMilliseconds() / 1000))
Range.NSRange\location = Len(GetGadgetText(0))
CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @Range)
EndIf
EndSelect
EndSelect
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIfWindows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Threads running on OS X 10.9
Thanks Wilbert but my app has a little more "string information" then just ElapsedMilliseconds(). That's why I have the AddGadgetItem() within the thread. This was just a smaller example code posted here. Is there no way to have AddGadgetItem() within the thread on OS X 10.9?
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: Threads running on OS X 10.9
It might help to add the lines using CocoaMessage
Code: Select all
Global.i TextView, TextStorage
Procedure Run(Parameter)
StartTime = ElapsedMilliseconds()
Repeat
If ElapsedMilliseconds() - StartTime >= 1000
StartTime = ElapsedMilliseconds()
ItemString.s = Str(ElapsedMilliseconds() / 1000) + #LF$
AttrString = CocoaMessage(0, CocoaMessage(0, 0, "NSAttributedString alloc"), "initWithString:$", @ItemString)
CocoaMessage(0, TextStorage, "appendAttributedString:", AttrString)
CocoaMessage(0, AttrString, "release")
PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_Change)
EndIf
Delay(1)
ForEver
EndProcedure
If OpenWindow(0, 0, 0, 420, 270, "Thread Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 400, 250)
TextView = GadgetID(0)
TextStorage = CocoaMessage(0, TextView, "textStorage")
CreateThread(@Run(), Parameter)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change
CocoaMessage(@Range.NSRange\location, TextStorage, "length")
CocoaMessage(0, TextView, "scrollRangeToVisible:@", @Range)
EndIf
EndSelect
EndSelect
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIfWindows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Threads running on OS X 10.9
Thanks Wilbert, that works great! I'll have to try it in my app now. 
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: Threads running on OS X 10.9
The advantage of this attributed string approach is that you can also format the text you add.
Code: Select all
#NSItalicFontMask = 1
#NSBoldFontMask = 2
Global.i TextView, TextStorage
Procedure Run(Parameter)
StartTime = ElapsedMilliseconds()
Repeat
If ElapsedMilliseconds() - StartTime >= 1000
StartTime = ElapsedMilliseconds()
ItemString.s = Str(ElapsedMilliseconds() / 1000) + #LF$
AttrString = CocoaMessage(0, CocoaMessage(0, 0, "NSMutableAttributedString alloc"), "initWithString:$", @ItemString)
CocoaMessage(@AttrRange.NSRange\length, AttrString, "length")
CocoaMessage(0, AttrString, "applyFontTraits:", #NSBoldFontMask | #NSItalicFontMask, "range:@", @AttrRange)
CocoaMessage(0, TextStorage, "appendAttributedString:", AttrString)
CocoaMessage(0, AttrString, "release")
PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_Change)
EndIf
Delay(1)
ForEver
EndProcedure
If OpenWindow(0, 0, 0, 420, 270, "Thread Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 400, 250)
TextView = GadgetID(0)
TextStorage = CocoaMessage(0, TextView, "textStorage")
CreateThread(@Run(), Parameter)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change
CocoaMessage(@Range.NSRange\location, TextStorage, "length")
CocoaMessage(0, TextView, "scrollRangeToVisible:@", @Range)
EndIf
EndSelect
EndSelect
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIfWindows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Threads running on OS X 10.9
Very nice, thanks again! 
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: Threads running on OS X 10.9
The CocoaMessage() fixed the AddGadgetItem() error but threads still crash on OS X 10.9.3 for some reason. Still looking into this.
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.

