Window displays on OSx with Carbon, but not with Cocoa

When I changed the Framework from Carbon to Cocoa it no longer displays my starting screen. I show a splash screen which works fine, and then the app uses a timer event to close the splash screen and the starting screen for the app is supposed to display. I am not getting any errors and I even built the app without any errors, although when I try to run the built app file it does same thing (shows splash screen but then not the main screen). I do see the icon in the docking area.

Perhaps I am missing something really simple but it works fine with Carbon and not starting out so good with Cocoa. My Mac OS X is 10.9.4. Any suggestions are much appreciated.

Here is code from the Open Event and also from the Timer, which gets triggered when the Splash screen is closed. Apologies that it is a little more than a snippet but perhaps there is something obvious sticking out that isn’t obvious to me. :slight_smile:

[code] Dim ScreenHeight As Integer
Dim ScreenWidth As Integer

'save screen resolution
app.ScreenHeight = Screen(0).Height
app.ScreenWidth = Screen(0).Width
app.AutoQuit = True

'get current date for future usage
now3 = new date
l =Len( Str(now3.Month))
If l = 1 Then
app.CurrentDate = “0”
app.CurrentDate = app.CurrentDate + Str(now3.Month)
Else
app.CurrentDate = Str(now3.Month)
End If
app.CurrentDate = app.CurrentDate + “/”
l = Len(Str(now3.Day))
If l = 1 Then
app.CurrentDate = app.CurrentDate + “0”
app.CurrentDate = app.CurrentDate + Str(now3.Day)
Else
app.CurrentDate = app.CurrentDate + Str(now3.Day)
End If
app.CurrentDate = app.CurrentDate + “/”
app.CurrentDate = app.CurrentDate + Str(now3.year)

Dim ScreenHeight As Integer
Dim ScreenWidth As Integer

'save screen resolution
app.ScreenHeight = Screen(0).Height
app.ScreenWidth = Screen(0).Width
app.AutoQuit = True

'get current date for future usage
now3 = new date
l =Len( Str(now3.Month))
If l = 1 Then
app.CurrentDate = “0”
app.CurrentDate = app.CurrentDate + Str(now3.Month)
Else
app.CurrentDate = Str(now3.Month)
End If
app.CurrentDate = app.CurrentDate + “/”
l = Len(Str(now3.Day))
If l = 1 Then
app.CurrentDate = app.CurrentDate + “0”
app.CurrentDate = app.CurrentDate + Str(now3.Day)
Else
app.CurrentDate = app.CurrentDate + Str(now3.Day)
End If
app.CurrentDate = app.CurrentDate + “/”
app.CurrentDate = app.CurrentDate + Str(now3.year)

WindowMainMenu.Visible =False

LabelTextColor = LabelAutoSizeGame1.TextColor 'save default text color for all main menu labels
'assign text so label can resize
LabelAutoSizeSeasons1.Text = "Set Active Season "
LabelAutoSizeSeasons2.Text = "Team Management/Profile -> "

LabelAutoSizeSeasons3.Text = “League/Season Tools”
LabelAutoSizeSeasons4.Text = "SIBB Chart Tools (advanced) "
LabelAutoSizeSeasons5.Text = "Era Normalization (advanced) "
LabelAutoSizeSetting1.Text = "Settings and Preferences (global) "
LabelAutoSizeReport1.Text = “League Reports”
LabelAutoSizeReport2.Text = "Export Reports to File "
LabelAutoSizeReport3.Text = "Build League Website "

#if TargetMacOS
app.CommonPath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Data”).Child(“Common”)
app.SeasonsPath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Data”).Child(“Seasons”)
app.HelpPath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Help”)
app.BallparkImagePath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Ballpark Images”)
app.PlayerImagePath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Player Images”)
app.TeamImagePath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Team Images”)
app.SoundFilesPath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Sound Files”)
app.ImportPath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Data”).Child(“Import”)
app.BackdropPath = SpecialFolder.ApplicationData.Child(“Dombrov Baseball Sim”).Child(“Backdrops”)

#else
app.CommonPath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Data”).Child(“Common”)
app.SeasonsPath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Data”).Child(“Seasons”)
app.HelpPath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Help”)
app.BallparkImagePath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Ballpark Images”)
app.PlayerImagePath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Player Images”)
app.TeamImagePath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Team Images”)
app.SoundFilesPath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Sound Files”)
app.ImportPath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Data”).Child(“Import”)
app.BackdropPath = SpecialFolder.Documents.Child(“Dombrov Baseball Sim”).Child(“Backdrops”)
#endif

'connect SQLite common database

app.dbcOpen = False
rtn = app.ConnectCommon

if rtn = False Then
Exit Sub
End If

'load game play settings
rtn = app.LoadGameSettings

if rtn = False Then
Exit Sub
End If

'set backdrop and screen text colors
mImage = app.MainScreenImage
CanvasBackdrop.Backdrop = app.MainScreenImage
LabelAutoSizeGame1.TextColor = app.MainScreensTextColor
LabelAutoSizeGame2.TextColor = app.MainScreensTextColor
LabelAutoSizeGame3.TextColor = app.MainScreensTextColor
LabelAutoSizeGame4.TextColor = app.MainScreensTextColor
LabelAutoSizeSeasons1.TextColor = app.MainScreensTextColor
LabelAutoSizeSeasons2.TextColor = app.MainScreensTextColor
LabelAutoSizeSeasons3.TextColor = app.MainScreensTextColor
LabelAutoSizeSeasons4.TextColor = app.MainScreensTextColor
LabelAutoSizeSeasons5.TextColor = app.MainScreensTextColor
LabelAutoSizeSetting1.TextColor = app.MainScreensTextColor
LabelAutoSizeReport1.TextColor = app.MainScreensTextColor
LabelAutoSizeReport2.TextColor = app.MainScreensTextColor
LabelAutoSizeReport3.TextColor = app.MainScreensTextColor
LabelSettings.TextColor = app.MainScreensHeaderColor
LabelSeason.TextColor = app.MainScreensHeaderColor
LabelGamePlay.TextColor = app.MainScreensHeaderColor
LabelReports.TextColor = app.MainScreensHeaderColor
LabelWindowHeader.TextColor = app.MainScreensHeaderColor
HoverColor = app.MainScreensHoverColor

'splash screen and opening sound
'WindowSplash.ShowWithin(WindowMainMenu)
If app.GameSettings.IntroSound <> “” Then
sf = app.SoundFilesPath.Child(app.GameSettings.IntroSound)
If sf <> Nil Then
if sf.Exists Then
snd = sf.OpenAsSound
snd.Play
End If
End If
End If

'load active season
rtn = app.CheckForActiveSeason
if rtn = False Then
Exit Sub
End If
rtn = app.BuildBallparks
if rtn = False Then
Exit Sub
End If

app.Randomizer = New Random

'show splash screen interval
'splash screen and opening sound
WindowMainMenu.Visible =False
WindowSplash.Show

Timer1.Mode = Timer.ModeSingle
Timer1.Period = 2500

'------------------------------------------------------------------------------------------------
‘’ this is code from the Timer Action event (triggered 2.5 seconds after the Open event for the main window)
WindowSplash.Close

WindowMainMenu.Visible =True

WindowMainMenu.Width = app.ScreenWidth
WindowMainMenu.Height = app.ScreenHeight
WindowMainMenu.TextAreaClose.Left = (WindowMainMenu.Width - 124)
WindowMainMenu.CanvasHelp.Left = (WindowMainMenu.Width - 38)
WindowMainMenu.Maximize

If app.GameSettings.FreeEdition = True Then
WindowFreeEdition.ShowModalWithin(WindowMainMenu)
End If
[/code]

The FreeEdition indicator is closed so it isn’t trying to show WindowFreeEdition

WindowMainMenu is setup as a Frame Type of Document.

Thanks,

Richard

There is no code in there like WindowMainMenu.Show. So is this long piece of code in App.Open or in WindowMainMenu.Open ?

This whole thing is too crowded.

Can’t you simply test in a project with only the code to display the windows ? Would that not be a bit simpler ? Then you will know if it is a display issue or a code issue.

I encouraged him to start a new topic (from the carbon death thread) and post some code so we could look into it as a community. Not everyone knows what to post, or how to use [ code ] blocks, so be kind.

Michel has caught it though, I don’t see where you would have opened WindowMainMenu. I do see WindowMainMenu.Visible =False early on, and WindowMainMenu.Visible =True toward the end. I’m actually not sure if .visible=true has the same effect as .show() (I just haven’t been part of Xojo long enough to know)

Try this:
In the IDE, click your main App object and check the inspector. What do you have set for DefaultWindow? If it’s “None” that would be why your app isn’t opening a window, but we can use this for good. If it’s WindowMainMenu, we may have a problem.

Try setting DefaultWindow to “None” and in your open code, instead of using .visible=false and .visible=true, use window.show() once you’ve got everything set up at the end. It would reduce the chance of a window flicker.

Richard, I’ve edited your post to use a code block, though for some reason I couldn’t use two code blocks (it just came out looking wrong). I’ve separated the two with a bunch of dashes.

The code looks like it contains duplicate sections because ScreenHeight and ScreenWidth are declared twice (AND are properties of the app).

+1 for Michels idea.

You might want to consider moving app.autoquit to somewhere later in your code as well. (Like in your mainwindow open event). It may be that the app is trying to close in the brief moment when no windows are open.

You know what ? Add the following lines at the beginning of your code :

WindowMainMenu.Show WindowSplash.Show Return

If both windows display fine, then it is not a Cocoa problem.

Thanks for all of the responses. This window is the default window for the app which is the reason I didn’t think I needed the Show method, although no big deal if it needs to be there. I was able to get the screen to display by simply moving the code that was in the Timer Action event in to my window open event, replacing the timer period with a sleepcurrentthread for the same duration.

Something else I noticed, any place where I am displaying another Window, I am setting windowmainmenu.visible = False, and when that other window closes, I am setting windowmainmenu.visible = True. This was working with Carbon, and on Windows 7/8, but it doesn’t work with Cocoa. I have been able to get past that by changing windowmainmenu.visible = True to windowmainmenu.Show.

I’m not necessarily trying to suggest there is an issue with Cocoa and I understand if I need to make some changes in my code. But if anyone is aware of a checklist or guidelines with developing an app using Cocoa versus Carbon that would be great, although I also want this app to work on Windows 7/8 which is where my entire user base currently resides. I was sort of expecting some differences but what I have found so far seems a little strange. I suppose one of my options is to stay on Carbon with XOJO 2014R2 although I’m licensed through most of next year so I’d like to keep current with the updates.

Thanks for the suggestions, I did try just having the Show method in the Open event and that works but who wants an app that doesn’t do anything? :slight_smile: I also tried moving (and even removing) the app.autoquit = true but that didn’t make a difference. Thankfully it is working by taking the code out of the timer Action event but not sure I understand why that is making a difference.

Regards,

Richard

You already found out that window.visible should be replaced by window.show.

The goal of the test was to see if the issue of the window not appearing was a bug in Xojo Cocoa, or if it was a problem with your code. Now you know where to look.

There is no precise list of what works and does not work in Cocoa. We all switched to Cocoa built and discovered what needed to be changed as we went along.