ToolBar: App crashing if ToolBarItem is clicked while Icon changes

If have a ToolBar in my main Window which is controlled by a Timer in the same window, changing the Icon of one of the ToolBar Buttons:

The Timer Action:

[code] If myUpdateInProgress Then

If MainToolbar.myDatabaseItem.Icon = mydbIcon_64_Updating_01 Then
  MainToolbar.myDatabaseItem.Icon = mydbIcon_64_Updating_02
Else
  MainToolbar.myDatabaseItem.Icon = mydbIcon_64_Updating_01
End If

Else

MainToolbar.myDatabaseItem.Icon = mydbIcon_64
Me.Mode = 0

End If[/code]

If i do a long click or a click in the “wrong moment” on this Button, the app crashes.

OS X Reports:

[code]Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000008fe00000
[/code]

Atm i am simply disabling the Button until the Timer brings it self into Mode=0…

How can i make sure the user is not clicking the Button in the “wrong moment” or make sure the Icon changes are no problem?

BTW: My main goal is to have an animated ToolBar Icon while a specific Thread is working.

bug report with the full crash log would be best

I guess the timer ticks like once a second or so, to show icons changing…

Why don’t you add a second, faster timer, which will be in charge of monitoring and managing your button action ?

  • In the button, just set a module boolean flag to true (“buttonClicked”)
  • In the button timer ;

if TimerIcon mode <> 0 then return //I call "TimerIcon" the original one where icons are switched if buttonClicked = True then doYourStuff //method where you do what was before in the button buttonClicked = False end if

This would avoid the button to become inactive at the moment the user clicks, while preventing execution while TimerIcon is fired.
I just hope the crash is only due to clicking while the icons are changed.

Done + added an example: <https://xojo.com/issue/33390>

Exactly.

Thank you Michel. :slight_smile:

yeah I can confirm this one
wrote my own which just rotates between 3 images & all you have to do is click as the images are being changed
not sure if this is only cocoa or not

Thank you Norman.