problem with selectColor

Hello,

64-bit, Xojo 18r4, Mojave 10.14.2

I notice that after executing the code below, and dismissing the Color window either clicking Cancel or OK, next time I run the debugger the Color window keeps popping up.

//action event of a pushButton
dim c as color = color.red
if selectColor(c,"") then
end if

I cleared Xojo cache, trashed the preferences file of the app, restarted Xojo. Yet, when I run that app in the debugger, the Color window is there to greet me.
To be precise: the Color window shows without its Cancel and OK buttons.
I recall this happened also when launching the built apps (yep, I have a couple of projects showing this behavior).

Unfortunately I cannot reproduce this behavior in a fresh project.
Suggestions appreciated. Thanks.

Is this solved?

Searched the forums and found this. I’ve got the exact same problem now in a project I need to build soon. Adding one call to SelectColor in one location has resulted in the color picker appearing at launch in both the debugger and in compiled macOS apps. This happens even if I remove the line of code that calls SelectColor. I’ve also found that the color picker opens before the App.Open event fires.

I’ve tried changing the properties of the window which calls it (implicit; not implicit; visible/invisible; etc) to no effect. I’m at a loss as to what to try next or why this would ever happen.

Thank Apple
There was another thread about this - let me see if I can find it

edit : https://forum.xojo.com/56285-catalina-color-panel

Would love to read the other thread if you find it. After 20m of frustration I make my post…try toggling Visible again…and the problem disappears (for now?).

Is it a state problem on a particular machine? In other words if I had copied the binary to another Mac, or restarted my Mac, and launched the binary would it have been fine?

there is / was some decalre you could call to close the system async color selector window
basically thats what is hanging around and apple records that it is / was open in your app’s plist when it quits and the plist is finally synced
then when you open there it is

or you can switch to using the MBS one and it doesnt do this

Thank you!

In the closeCancel event handler of each window calling selectcolor I call the following code (thanks to Sam!):
BTW: I use NSColorWell (macOSLib 64bit) to show the selectcolor pane.

Public Sub closeNSColorPanel() #if TargetMacOS then declare function NSClassFromString lib "AppKit" ( className as CFStringRef ) as ptr declare function sharedColorPanel lib "AppKit" selector "sharedColorPanel" ( classRef as Ptr ) as Ptr declare sub close lib "AppKit" selector "close" ( panel as Ptr ) close( sharedColorPanel( NSClassFromString( "NSColorPanel" ) ) ) #endif End Sub

Thank you Carlo!

@Daniel Taylor, @Carlo Rubini — I think you should use sharedColorPanelExists, which checks whether the color panel exists without creating one. Calling sharedColorPanel creates one if it doesn’t already exist.

[code]Public Sub closeNSColorPanel()
#if TargetMacOS then
declare function NSClassFromString lib “AppKit” ( className as CFStringRef ) as ptr
declare function sharedColorPanel lib “AppKit” selector “sharedColorPanel” ( classRef as Ptr ) as Ptr
declare sub close lib “AppKit” selector “close” ( panel as Ptr )
declare function sharedColorPanelExists lib “AppKit” ( classRef as Ptr ) as Boolean

if sharedColorPanelExists then
    close( sharedColorPanel( NSClassFromString( "NSColorPanel" ) ) )
end if

#endif
End Sub[/code]

@Daniel Taylor

That is, thank you @Sam Rowlands for the original snippet and thank you @Stéphane Mons for the update.

@Stphane Mons: running your suggested code, I get a "Not enough arguments: missing Ptr value for parameter “Class Ref” warning/error at:

if sharedColorPanelExists then//<<<< here

Any suggestion how to fix it?

Thanks

[quote=472602:@Carlo Rubini]@Stéphane Mons: running your suggested code, I get a "Not enough arguments: missing Ptr value for parameter “Class Ref” warning/error at:

if sharedColorPanelExists then//<<<< here

Any suggestion how to fix it?[/quote]

I would assume NSClassFromString( “NSColorPanel” ) would return the proper pointer value for sharedColorPanelExists. But when I try it I actually get a linker error and compilation cannot complete.

Carlo’s original code seems to be working for me even if it unnecessarily creates and then closes a color panel.