More SDL + Mac questions

Mac OSX specific forum
User avatar
kenmo
Addict
Addict
Posts: 2081
Joined: Tue Dec 23, 2003 3:54 am

More SDL + Mac questions

Post by kenmo »

I'm still experimenting with SDL + PureBasic, and I have two new Mac-only issues... any ideas?

1. No QUIT events from "Quit" menu item or Cmd+Q

The SDL documentation (and users on their forum) say that SDL should automatically post #SDL_QUIT events when a window's close button is pressed, Quit is selected from the main menu, or Cmd+Q is pressed. But when creating a SDL window in PB, I only get #SDL_QUIT events for the first case (close button). Maybe PureBasic is consuming the menu and shortcut events, so the SDL backend doesn't receive them?? Is there a clever Cocoa way to catch these events?


2. SDL expects UTF8 strings, but I have to pass p-ascii or I get IMA crashes

When importing SDL functions that have string arguments, the documentations specify UTF8 but PureBasic's p-utf8 seems to crash, only p-ascii works for me. Maybe a bug in the way SDL passes p-utf8 strings on Mac?

Compiled in ASCII mode:
p-utf8: Invalid Memory Access when function is called
p-ascii: OK (but can't use characters above ASCII set)
p-unicode: IMA

Compiled in Unicode mode (preferred):
p-utf8: IMA
p-ascii: IMA
p-unicode: No crash, but since SDL expects UTF8, only the first character works



My test case is PB 5.30 + SDL 2.0.3. Soon SDL 2.0.4 will be released, I don't know how it will behave with PureBasic.

Both issues can be tested with the following code and the SDL for Mac framework: http://www.libsdl.org/release/SDL2-2.0.3.dmg

Code: Select all

Macro SDL_String
  p-ascii
  ;p-utf8
  ;p-unicode
EndMacro

ImportC "/Library/Frameworks/SDL2.framework/SDL2"
  SDL_Init.i(flags.l)
  SDL_Quit()
  SDL_CreateWindow.i(title.SDL_String, x.i, y.i, w.i, h.i, flags.l)
  SDL_DestroyWindow(*window)
  SDL_PollEvent.i(*event)
EndImport

#SDL_INIT_VIDEO = $20

#SDL_QUIT = $100

Structure SDL_Event
  StructureUnion
    type.l
    padding.a[56]
  EndStructureUnion
EndStructure

CompilerIf (#PB_Compiler_Unicode)
  MessageRequester("SDL Import", "Unicode is ON")
CompilerElse
  MessageRequester("SDL Import", "Unicode is OFF")
CompilerEndIf

If (SDL_Init(#SDL_INIT_VIDEO) = 0)
  *win = SDL_CreateWindow("SDL_Window", 100, 100, 640, 480, 0)
  If (*win)
    Event.SDL_Event
    Repeat
      While SDL_PollEvent(@Event)
        If (Event\type = #SDL_QUIT)
          Done = #True
        EndIf
      Wend
    Until Done
    SDL_DestroyWindow(*win)
  EndIf
  SDL_Quit()
EndIf
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: More SDL + Mac questions

Post by wilbert »

1. Can't you use the #PB_Menu_Quit event ?

2. There's a bug with pseudotype.
I was hoping Fred would fix it for the 5.30 or LTS release but so far this hasn't happened unfortunately :(
http://www.purebasic.fr/english/viewtop ... 24&t=58786
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
kenmo
Addict
Addict
Posts: 2081
Joined: Tue Dec 23, 2003 3:54 am

Re: More SDL + Mac questions

Post by kenmo »

1. :shock: I thought I tried this before... but I tried again tonight and it works! (I had to create a hidden PB window, to use WindowEvent(), since SDL creates its own window.) I think I was accidentally checking for #PB_Event_CloseWindow, not #PB_Event_Menu + #PB_Menu_Quit.

So that's a solution. Thanks for the suggestion! Still strange that it doesn't trigger #SDL_QUIT like the close button does.

2. Oops, I didn't realize this had been posted before. Hopefully to be fixed in PB 5.31 ?
Post Reply