Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
parent
31257842ec
commit
caad673f06
|
@ -90,6 +90,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
|||
joystick->nballs = 0;
|
||||
joystick->nbuttons = 0;
|
||||
|
||||
@autoreleasepool {
|
||||
if (motionManager == nil) {
|
||||
motionManager = [[CMMotionManager alloc] init];
|
||||
}
|
||||
|
@ -97,6 +98,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
|||
/* Shorter times between updates can significantly increase CPU usage. */
|
||||
motionManager.accelerometerUpdateInterval = 0.1;
|
||||
[motionManager startAccelerometerUpdates];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -113,11 +115,13 @@ static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
|
|||
const SInt16 maxsint16 = 0x7FFF;
|
||||
CMAcceleration accel;
|
||||
|
||||
@autoreleasepool {
|
||||
if (!motionManager.accelerometerActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
accel = [[motionManager accelerometerData] acceleration];
|
||||
accel = motionManager.accelerometerData.acceleration;
|
||||
}
|
||||
|
||||
/*
|
||||
Convert accelerometer data from floating point to Sint16, which is what
|
||||
|
@ -161,7 +165,9 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
|||
void
|
||||
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
|
||||
{
|
||||
@autoreleasepool {
|
||||
[motionManager stopAccelerometerUpdates];
|
||||
}
|
||||
joystick->closed = 1;
|
||||
}
|
||||
|
||||
|
@ -169,10 +175,12 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick)
|
|||
void
|
||||
SDL_SYS_JoystickQuit(void)
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (motionManager != nil) {
|
||||
[motionManager release];
|
||||
motionManager = nil;
|
||||
}
|
||||
}
|
||||
|
||||
numjoysticks = 0;
|
||||
}
|
||||
|
|
|
@ -50,11 +50,12 @@ SDL_UIKit_UpdateBatteryMonitoring(void)
|
|||
SDL_bool
|
||||
SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
|
||||
{
|
||||
@autoreleasepool {
|
||||
UIDevice *uidev = [UIDevice currentDevice];
|
||||
|
||||
if (!SDL_UIKitLastPowerInfoQuery) {
|
||||
SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
|
||||
[uidev setBatteryMonitoringEnabled:YES];
|
||||
SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
|
||||
uidev.batteryMonitoringEnabled = YES;
|
||||
}
|
||||
|
||||
/* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
|
||||
|
@ -66,8 +67,7 @@ SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
|
|||
|
||||
*seconds = -1; /* no API to estimate this in UIKit. */
|
||||
|
||||
switch ([uidev batteryState])
|
||||
{
|
||||
switch (uidev.batteryState) {
|
||||
case UIDeviceBatteryStateCharging:
|
||||
*state = SDL_POWERSTATE_CHARGING;
|
||||
break;
|
||||
|
@ -86,10 +86,11 @@ SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
|
|||
break;
|
||||
}
|
||||
|
||||
const float level = [uidev batteryLevel];
|
||||
const float level = uidev.batteryLevel;
|
||||
*percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
|
||||
return SDL_TRUE; /* always the definitive answer on iOS. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_UIKIT */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
|
|
|
@ -159,11 +159,13 @@ UIKit_IsDisplayLandscape(UIScreen *uiscreen)
|
|||
int
|
||||
UIKit_InitModes(_THIS)
|
||||
{
|
||||
@autoreleasepool {
|
||||
for (UIScreen *uiscreen in [UIScreen screens]) {
|
||||
if (UIKit_AddDisplay(uiscreen) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -173,6 +175,7 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
|||
{
|
||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||
|
||||
@autoreleasepool {
|
||||
SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
|
||||
SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
|
||||
CGFloat scale = data->uiscreen.scale;
|
||||
|
@ -195,6 +198,7 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
|||
UIKit_AddDisplayMode(display, w, h, uimode, addRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
||||
|
@ -202,6 +206,7 @@ UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
|||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
|
||||
|
||||
@autoreleasepool {
|
||||
[data->uiscreen setCurrentMode:modedata->uiscreenmode];
|
||||
|
||||
if (data->uiscreen == [UIScreen mainScreen]) {
|
||||
|
@ -215,6 +220,7 @@ UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -224,6 +230,7 @@ UIKit_QuitModes(_THIS)
|
|||
{
|
||||
/* Release Objective-C objects, so higher level doesn't free() them. */
|
||||
int i, j;
|
||||
@autoreleasepool {
|
||||
for (i = 0; i < _this->num_displays; i++) {
|
||||
SDL_VideoDisplay *display = &_this->displays[i];
|
||||
|
||||
|
@ -239,6 +246,7 @@ UIKit_QuitModes(_THIS)
|
|||
display->driverdata = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ UIKit_GL_GetProcAddress(_THIS, const char *proc)
|
|||
int
|
||||
UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (context) {
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
[data->view setCurrentContext];
|
||||
|
@ -59,6 +60,7 @@ UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
|||
else {
|
||||
[EAGLContext setCurrentContext: nil];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -67,6 +69,7 @@ void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
|||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
|
||||
@autoreleasepool {
|
||||
if (w) {
|
||||
*w = data->view.backingWidth;
|
||||
}
|
||||
|
@ -74,6 +77,7 @@ void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
|||
*h = data->view.backingHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
|
@ -92,6 +96,7 @@ UIKit_GL_LoadLibrary(_THIS, const char *path)
|
|||
|
||||
void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
#if SDL_POWER_UIKIT
|
||||
/* Check once a frame to see if we should turn off the battery monitor. */
|
||||
SDL_UIKit_UpdateBatteryMonitoring();
|
||||
|
@ -109,10 +114,12 @@ void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
|
|||
(low memory, terminate, etc.) to happen inside low level rendering.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GLContext
|
||||
UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_uikitopenglview *view;
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
UIWindow *uiwindow = data->uiwindow;
|
||||
|
@ -176,10 +183,12 @@ UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
|
||||
{
|
||||
@autoreleasepool {
|
||||
/* the delegate has retained the view, this will release him */
|
||||
SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
|
||||
if (view->viewcontroller) {
|
||||
|
@ -193,6 +202,7 @@ UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
|
|||
[view removeFromSuperview];
|
||||
[view release];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||
|
||||
|
|
|
@ -318,22 +318,27 @@ SDL_bool UIKit_HasScreenKeyboardSupport(_THIS)
|
|||
|
||||
void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_uikitview *view = getWindowView(window);
|
||||
if (view != nil) {
|
||||
[view showKeyboard];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_uikitview *view = getWindowView(window);
|
||||
if (view != nil) {
|
||||
[view hideKeyboard];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_uikitview *view = getWindowView(window);
|
||||
if (view == nil) {
|
||||
return 0;
|
||||
|
@ -341,6 +346,7 @@ SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
|
|||
|
||||
return view.isKeyboardVisible;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _uikit_keyboard_update() {
|
||||
|
@ -424,6 +430,7 @@ UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
|
|||
return;
|
||||
}
|
||||
|
||||
@autoreleasepool {
|
||||
SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
|
||||
if (view == nil) {
|
||||
return;
|
||||
|
@ -431,6 +438,7 @@ UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
|
|||
|
||||
view.textInputRect = *rect;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* SDL_IPHONE_KEYBOARD */
|
||||
|
|
|
@ -132,6 +132,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow,
|
|||
int
|
||||
UIKit_CreateWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||
const BOOL external = ([UIScreen mainScreen] != data->uiscreen);
|
||||
|
@ -211,6 +212,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
|
|||
[uiwindow release];
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -218,18 +220,22 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
|
|||
void
|
||||
UIKit_ShowWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
|
||||
|
||||
[uiwindow makeKeyAndVisible];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UIKit_HideWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
|
||||
|
||||
uiwindow.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UIKit_RaiseWindow(_THIS, SDL_Window * window)
|
||||
|
@ -286,31 +292,39 @@ UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
|
|||
void
|
||||
UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
||||
{
|
||||
@autoreleasepool {
|
||||
UIKit_UpdateWindowBorder(_this, window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
||||
{
|
||||
@autoreleasepool {
|
||||
UIKit_UpdateWindowBorder(_this, window);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UIKit_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
|
||||
@autoreleasepool {
|
||||
if (data) {
|
||||
[data->viewcontroller release];
|
||||
[data->uiwindow release];
|
||||
SDL_free(data);
|
||||
}
|
||||
}
|
||||
|
||||
window->driverdata = NULL;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
||||
{
|
||||
@autoreleasepool {
|
||||
UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
|
||||
|
||||
if (info->version.major <= SDL_MAJOR_VERSION) {
|
||||
|
@ -323,6 +337,7 @@ UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
|||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
|
||||
|
@ -333,7 +348,10 @@ SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callbac
|
|||
return SDL_SetError("Invalid window or view not set");
|
||||
}
|
||||
|
||||
@autoreleasepool {
|
||||
[data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue