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
