Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m
index 31b4e84..c08dec1 100644
--- a/src/joystick/iphoneos/SDL_sysjoystick.m
+++ b/src/joystick/iphoneos/SDL_sysjoystick.m
@@ -90,14 +90,16 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
joystick->nballs = 0;
joystick->nbuttons = 0;
- if (motionManager == nil) {
- motionManager = [[CMMotionManager alloc] init];
+ @autoreleasepool {
+ if (motionManager == nil) {
+ motionManager = [[CMMotionManager alloc] init];
+ }
+
+ /* Shorter times between updates can significantly increase CPU usage. */
+ motionManager.accelerometerUpdateInterval = 0.1;
+ [motionManager startAccelerometerUpdates];
}
- /* 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;
- if (!motionManager.accelerometerActive) {
- return;
- }
+ @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)
{
- [motionManager stopAccelerometerUpdates];
+ @autoreleasepool {
+ [motionManager stopAccelerometerUpdates];
+ }
joystick->closed = 1;
}
@@ -169,9 +175,11 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick)
void
SDL_SYS_JoystickQuit(void)
{
- if (motionManager != nil) {
- [motionManager release];
- motionManager = nil;
+ @autoreleasepool {
+ if (motionManager != nil) {
+ [motionManager release];
+ motionManager = nil;
+ }
}
numjoysticks = 0;
diff --git a/src/power/uikit/SDL_syspower.m b/src/power/uikit/SDL_syspower.m
index 60c4274..4984b78 100644
--- a/src/power/uikit/SDL_syspower.m
+++ b/src/power/uikit/SDL_syspower.m
@@ -50,24 +50,24 @@ SDL_UIKit_UpdateBatteryMonitoring(void)
SDL_bool
SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
{
- UIDevice *uidev = [UIDevice currentDevice];
+ @autoreleasepool {
+ UIDevice *uidev = [UIDevice currentDevice];
- if (!SDL_UIKitLastPowerInfoQuery) {
- SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
- [uidev setBatteryMonitoringEnabled:YES];
- }
+ if (!SDL_UIKitLastPowerInfoQuery) {
+ SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
+ uidev.batteryMonitoringEnabled = YES;
+ }
- /* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
- * monitoring if the app hasn't queried it in the last X seconds.
- * Apparently monitoring the battery burns battery life. :)
- * Apple's docs say not to monitor the battery unless you need it.
- */
- SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
+ /* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
+ * monitoring if the app hasn't queried it in the last X seconds.
+ * Apparently monitoring the battery burns battery life. :)
+ * Apple's docs say not to monitor the battery unless you need it.
+ */
+ SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
- *seconds = -1; /* no API to estimate this in UIKit. */
+ *seconds = -1; /* no API to estimate this in UIKit. */
- switch ([uidev batteryState])
- {
+ switch (uidev.batteryState) {
case UIDeviceBatteryStateCharging:
*state = SDL_POWERSTATE_CHARGING;
break;
@@ -84,11 +84,12 @@ SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
default:
*state = SDL_POWERSTATE_UNKNOWN;
break;
- }
+ }
- const float level = [uidev batteryLevel];
- *percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
- return SDL_TRUE; /* always the definitive answer on iOS. */
+ 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 */
diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m
index 20a433d..e17e16a 100644
--- a/src/video/uikit/SDL_uikitmodes.m
+++ b/src/video/uikit/SDL_uikitmodes.m
@@ -159,9 +159,11 @@ UIKit_IsDisplayLandscape(UIScreen *uiscreen)
int
UIKit_InitModes(_THIS)
{
- for (UIScreen *uiscreen in [UIScreen screens]) {
- if (UIKit_AddDisplay(uiscreen) < 0) {
- return -1;
+ @autoreleasepool {
+ for (UIScreen *uiscreen in [UIScreen screens]) {
+ if (UIKit_AddDisplay(uiscreen) < 0) {
+ return -1;
+ }
}
}
@@ -173,26 +175,28 @@ UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
- SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
- SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
- CGFloat scale = data->uiscreen.scale;
-
- for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
- /* The size of a UIScreenMode is in pixels, but we deal exclusively in
- * points (except in SDL_GL_GetDrawableSize.) */
- CGSize size = [uimode size];
- int w = (int)(size.width / scale);
- int h = (int)(size.height / scale);
-
- /* Make sure the width/height are oriented correctly */
- if (isLandscape != (w > h)) {
- int tmp = w;
- w = h;
- h = tmp;
- }
+ @autoreleasepool {
+ SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
+ SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
+ CGFloat scale = data->uiscreen.scale;
+
+ for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
+ /* The size of a UIScreenMode is in pixels, but we deal exclusively in
+ * points (except in SDL_GL_GetDrawableSize.) */
+ CGSize size = [uimode size];
+ int w = (int)(size.width / scale);
+ int h = (int)(size.height / scale);
+
+ /* Make sure the width/height are oriented correctly */
+ if (isLandscape != (w > h)) {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ }
- /* Add the native screen resolution. */
- UIKit_AddDisplayMode(display, w, h, uimode, addRotation);
+ /* Add the native screen resolution. */
+ UIKit_AddDisplayMode(display, w, h, uimode, addRotation);
+ }
}
}
@@ -202,16 +206,18 @@ UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
- [data->uiscreen setCurrentMode:modedata->uiscreenmode];
-
- if (data->uiscreen == [UIScreen mainScreen]) {
- if (mode->w > mode->h) {
- if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
- }
- } else if (mode->w < mode->h) {
- if (UIKit_IsDisplayLandscape(data->uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
+ @autoreleasepool {
+ [data->uiscreen setCurrentMode:modedata->uiscreenmode];
+
+ if (data->uiscreen == [UIScreen mainScreen]) {
+ if (mode->w > mode->h) {
+ if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
+ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
+ }
+ } else if (mode->w < mode->h) {
+ if (UIKit_IsDisplayLandscape(data->uiscreen)) {
+ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
+ }
}
}
}
@@ -224,19 +230,21 @@ UIKit_QuitModes(_THIS)
{
/* Release Objective-C objects, so higher level doesn't free() them. */
int i, j;
- for (i = 0; i < _this->num_displays; i++) {
- SDL_VideoDisplay *display = &_this->displays[i];
+ @autoreleasepool {
+ for (i = 0; i < _this->num_displays; i++) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+
+ UIKit_FreeDisplayModeData(&display->desktop_mode);
+ for (j = 0; j < display->num_display_modes; j++) {
+ SDL_DisplayMode *mode = &display->display_modes[j];
+ UIKit_FreeDisplayModeData(mode);
+ }
- UIKit_FreeDisplayModeData(&display->desktop_mode);
- for (j = 0; j < display->num_display_modes; j++) {
- SDL_DisplayMode *mode = &display->display_modes[j];
- UIKit_FreeDisplayModeData(mode);
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ [data->uiscreen release];
+ SDL_free(data);
+ display->driverdata = NULL;
}
-
- SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
- [data->uiscreen release];
- SDL_free(data);
- display->driverdata = NULL;
}
}
diff --git a/src/video/uikit/SDL_uikitopengles.m b/src/video/uikit/SDL_uikitopengles.m
index 0b4a684..f17c831 100644
--- a/src/video/uikit/SDL_uikitopengles.m
+++ b/src/video/uikit/SDL_uikitopengles.m
@@ -52,12 +52,14 @@ UIKit_GL_GetProcAddress(_THIS, const char *proc)
int
UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
- if (context) {
- SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
- [data->view setCurrentContext];
- }
- else {
- [EAGLContext setCurrentContext: nil];
+ @autoreleasepool {
+ if (context) {
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ [data->view setCurrentContext];
+ }
+ else {
+ [EAGLContext setCurrentContext: nil];
+ }
}
return 0;
@@ -67,11 +69,13 @@ void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
- if (w) {
- *w = data->view.backingWidth;
- }
- if (h) {
- *h = data->view.backingHeight;
+ @autoreleasepool {
+ if (w) {
+ *w = data->view.backingWidth;
+ }
+ if (h) {
+ *h = data->view.backingHeight;
+ }
}
}
@@ -92,106 +96,112 @@ 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();
+ /* Check once a frame to see if we should turn off the battery monitor. */
+ SDL_UIKit_UpdateBatteryMonitoring();
#endif
- SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
- if (nil == data->view) {
- return;
- }
- [data->view swapBuffers];
+ if (nil == data->view) {
+ return;
+ }
+ [data->view swapBuffers];
- /* You need to pump events in order for the OS to make changes visible.
- We don't pump events here because we don't want iOS application events
- (low memory, terminate, etc.) to happen inside low level rendering.
- */
+ /* You need to pump events in order for the OS to make changes visible.
+ We don't pump events here because we don't want iOS application events
+ (low memory, terminate, etc.) to happen inside low level rendering.
+ */
+ }
}
SDL_GLContext
UIKit_GL_CreateContext(_THIS, SDL_Window * window)
{
- SDL_uikitopenglview *view;
- SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- UIWindow *uiwindow = data->uiwindow;
- CGRect frame = UIKit_ComputeViewFrame(window, uiwindow.screen);
- EAGLSharegroup *share_group = nil;
- CGFloat scale = 1.0;
-
- if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
- /* Set the scale to the natural scale factor of the screen - the backing
- dimensions of the OpenGL view will match the pixel dimensions of the
- screen rather than the dimensions in points.
- */
- scale = uiwindow.screen.scale;
- }
+ @autoreleasepool {
+ SDL_uikitopenglview *view;
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ UIWindow *uiwindow = data->uiwindow;
+ CGRect frame = UIKit_ComputeViewFrame(window, uiwindow.screen);
+ EAGLSharegroup *share_group = nil;
+ CGFloat scale = 1.0;
+
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ /* Set the scale to the natural scale factor of the screen - the backing
+ dimensions of the OpenGL view will match the pixel dimensions of the
+ screen rather than the dimensions in points.
+ */
+ scale = uiwindow.screen.scale;
+ }
- if (_this->gl_config.share_with_current_context) {
- SDL_uikitopenglview *view = (SDL_uikitopenglview *) SDL_GL_GetCurrentContext();
- share_group = [view.context sharegroup];
- }
+ if (_this->gl_config.share_with_current_context) {
+ SDL_uikitopenglview *view = (SDL_uikitopenglview *) SDL_GL_GetCurrentContext();
+ share_group = [view.context sharegroup];
+ }
- /* construct our view, passing in SDL's OpenGL configuration data */
- view = [[SDL_uikitopenglview alloc] initWithFrame: frame
- scale: scale
- retainBacking: _this->gl_config.retained_backing
- rBits: _this->gl_config.red_size
- gBits: _this->gl_config.green_size
- bBits: _this->gl_config.blue_size
- aBits: _this->gl_config.alpha_size
- depthBits: _this->gl_config.depth_size
- stencilBits: _this->gl_config.stencil_size
- sRGB: _this->gl_config.framebuffer_srgb_capable
- majorVersion: _this->gl_config.major_version
- shareGroup: share_group];
- if (!view) {
- return NULL;
- }
+ /* construct our view, passing in SDL's OpenGL configuration data */
+ view = [[SDL_uikitopenglview alloc] initWithFrame: frame
+ scale: scale
+ retainBacking: _this->gl_config.retained_backing
+ rBits: _this->gl_config.red_size
+ gBits: _this->gl_config.green_size
+ bBits: _this->gl_config.blue_size
+ aBits: _this->gl_config.alpha_size
+ depthBits: _this->gl_config.depth_size
+ stencilBits: _this->gl_config.stencil_size
+ sRGB: _this->gl_config.framebuffer_srgb_capable
+ majorVersion: _this->gl_config.major_version
+ shareGroup: share_group];
+ if (!view) {
+ return NULL;
+ }
- data->view = view;
- view->viewcontroller = data->viewcontroller;
- if (view->viewcontroller != nil) {
- [view->viewcontroller setView:view];
- [view->viewcontroller retain];
- }
- [uiwindow addSubview: view];
+ data->view = view;
+ view->viewcontroller = data->viewcontroller;
+ if (view->viewcontroller != nil) {
+ [view->viewcontroller setView:view];
+ [view->viewcontroller retain];
+ }
+ [uiwindow addSubview: view];
- /* The view controller needs to be the root in order to control rotation on iOS 6.0 */
- if (uiwindow.rootViewController == nil) {
- uiwindow.rootViewController = view->viewcontroller;
- }
+ /* The view controller needs to be the root in order to control rotation on iOS 6.0 */
+ if (uiwindow.rootViewController == nil) {
+ uiwindow.rootViewController = view->viewcontroller;
+ }
- if (UIKit_GL_MakeCurrent(_this, window, view) < 0) {
- UIKit_GL_DeleteContext(_this, view);
- return NULL;
- }
+ if (UIKit_GL_MakeCurrent(_this, window, view) < 0) {
+ UIKit_GL_DeleteContext(_this, view);
+ return NULL;
+ }
- /* Make this window the current mouse focus for touch input */
- if (uiwindow.screen == [UIScreen mainScreen]) {
- SDL_SetMouseFocus(window);
- SDL_SetKeyboardFocus(window);
- }
+ /* Make this window the current mouse focus for touch input */
+ if (uiwindow.screen == [UIScreen mainScreen]) {
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+ }
- return view;
+ return view;
+ }
}
void
UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
{
- /* the delegate has retained the view, this will release him */
- SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
- if (view->viewcontroller) {
- UIWindow *uiwindow = (UIWindow *)view.superview;
- if (uiwindow.rootViewController == view->viewcontroller) {
- uiwindow.rootViewController = nil;
+ @autoreleasepool {
+ /* the delegate has retained the view, this will release him */
+ SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
+ if (view->viewcontroller) {
+ UIWindow *uiwindow = (UIWindow *)view.superview;
+ if (uiwindow.rootViewController == view->viewcontroller) {
+ uiwindow.rootViewController = nil;
+ }
+ [view->viewcontroller setView:nil];
+ [view->viewcontroller release];
}
- [view->viewcontroller setView:nil];
- [view->viewcontroller release];
+ [view removeFromSuperview];
+ [view release];
}
- [view removeFromSuperview];
- [view release];
}
#endif /* SDL_VIDEO_DRIVER_UIKIT */
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index 620ea28..7267650 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -318,28 +318,34 @@ SDL_bool UIKit_HasScreenKeyboardSupport(_THIS)
void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
{
- SDL_uikitview *view = getWindowView(window);
- if (view != nil) {
- [view showKeyboard];
+ @autoreleasepool {
+ SDL_uikitview *view = getWindowView(window);
+ if (view != nil) {
+ [view showKeyboard];
+ }
}
}
void UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
{
- SDL_uikitview *view = getWindowView(window);
- if (view != nil) {
- [view hideKeyboard];
+ @autoreleasepool {
+ SDL_uikitview *view = getWindowView(window);
+ if (view != nil) {
+ [view hideKeyboard];
+ }
}
}
SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
{
- SDL_uikitview *view = getWindowView(window);
- if (view == nil) {
- return 0;
- }
+ @autoreleasepool {
+ SDL_uikitview *view = getWindowView(window);
+ if (view == nil) {
+ return 0;
+ }
- return view.isKeyboardVisible;
+ return view.isKeyboardVisible;
+ }
}
@@ -423,13 +429,15 @@ UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
SDL_InvalidParamError("rect");
return;
}
-
- SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
- if (view == nil) {
- return ;
- }
- view.textInputRect = *rect;
+ @autoreleasepool {
+ SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
+ if (view == nil) {
+ return;
+ }
+
+ view.textInputRect = *rect;
+ }
}
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index 7e3fac6..aed4a31 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -132,84 +132,86 @@ static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow,
int
UIKit_CreateWindow(_THIS, SDL_Window *window)
{
- SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
- SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
- const BOOL external = ([UIScreen mainScreen] != data->uiscreen);
- const CGSize origsize = [[data->uiscreen currentMode] size];
-
- /* SDL currently puts this window at the start of display's linked list. We rely on this. */
- SDL_assert(_this->windows == window);
-
- /* We currently only handle a single window per display on iOS */
- if (window->next != NULL) {
- return SDL_SetError("Only one window allowed per display.");
- }
-
- /* If monitor has a resolution of 0x0 (hasn't been explicitly set by the
- * user, so it's in standby), try to force the display to a resolution
- * that most closely matches the desired window size.
- */
- if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
- if (display->num_display_modes == 0) {
- _this->GetDisplayModes(_this, display);
+ @autoreleasepool {
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ const BOOL external = ([UIScreen mainScreen] != data->uiscreen);
+ const CGSize origsize = [[data->uiscreen currentMode] size];
+
+ /* SDL currently puts this window at the start of display's linked list. We rely on this. */
+ SDL_assert(_this->windows == window);
+
+ /* We currently only handle a single window per display on iOS */
+ if (window->next != NULL) {
+ return SDL_SetError("Only one window allowed per display.");
}
- int i;
- const SDL_DisplayMode *bestmode = NULL;
- for (i = display->num_display_modes; i >= 0; i--) {
- const SDL_DisplayMode *mode = &display->display_modes[i];
- if ((mode->w >= window->w) && (mode->h >= window->h))
- bestmode = mode;
- }
+ /* If monitor has a resolution of 0x0 (hasn't been explicitly set by the
+ * user, so it's in standby), try to force the display to a resolution
+ * that most closely matches the desired window size.
+ */
+ if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
+ if (display->num_display_modes == 0) {
+ _this->GetDisplayModes(_this, display);
+ }
- if (bestmode) {
- SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
- [data->uiscreen setCurrentMode:modedata->uiscreenmode];
+ int i;
+ const SDL_DisplayMode *bestmode = NULL;
+ for (i = display->num_display_modes; i >= 0; i--) {
+ const SDL_DisplayMode *mode = &display->display_modes[i];
+ if ((mode->w >= window->w) && (mode->h >= window->h))
+ bestmode = mode;
+ }
- /* desktop_mode doesn't change here (the higher level will
- * use it to set all the screens back to their defaults
- * upon window destruction, SDL_Quit(), etc.
- */
- display->current_mode = *bestmode;
- }
- }
+ if (bestmode) {
+ SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)bestmode->driverdata;
+ [data->uiscreen setCurrentMode:modedata->uiscreenmode];
- if (data->uiscreen == [UIScreen mainScreen]) {
- if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
- [UIApplication sharedApplication].statusBarHidden = YES;
- } else {
- [UIApplication sharedApplication].statusBarHidden = NO;
+ /* desktop_mode doesn't change here (the higher level will
+ * use it to set all the screens back to their defaults
+ * upon window destruction, SDL_Quit(), etc.
+ */
+ display->current_mode = *bestmode;
+ }
}
- }
- if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
- if (window->w > window->h) {
- if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
- }
- } else if (window->w < window->h) {
- if (UIKit_IsDisplayLandscape(data->uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
+ if (data->uiscreen == [UIScreen mainScreen]) {
+ if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
+ [UIApplication sharedApplication].statusBarHidden = YES;
+ } else {
+ [UIApplication sharedApplication].statusBarHidden = NO;
}
}
- }
- /* ignore the size user requested, and make a fullscreen window */
- /* !!! FIXME: can we have a smaller view? */
- SDL_uikitwindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data->uiscreen.bounds];
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ if (window->w > window->h) {
+ if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
+ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
+ }
+ } else if (window->w < window->h) {
+ if (UIKit_IsDisplayLandscape(data->uiscreen)) {
+ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
+ }
+ }
+ }
- /* put the window on an external display if appropriate. This implicitly
- * does [uiwindow setframe:[uiscreen bounds]], so don't do it on the
- * main display, where we land by default, as that would eat the
- * status bar real estate.
- */
- if (external) {
- [uiwindow setScreen:data->uiscreen];
- }
+ /* ignore the size user requested, and make a fullscreen window */
+ /* !!! FIXME: can we have a smaller view? */
+ SDL_uikitwindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data->uiscreen.bounds];
+
+ /* put the window on an external display if appropriate. This implicitly
+ * does [uiwindow setframe:[uiscreen bounds]], so don't do it on the
+ * main display, where we land by default, as that would eat the
+ * status bar real estate.
+ */
+ if (external) {
+ [uiwindow setScreen:data->uiscreen];
+ }
- if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
- [uiwindow release];
- return -1;
+ if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
+ [uiwindow release];
+ return -1;
+ }
}
return 1;
@@ -218,17 +220,21 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
void
UIKit_ShowWindow(_THIS, SDL_Window * window)
{
- UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
+ @autoreleasepool {
+ UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
- [uiwindow makeKeyAndVisible];
+ [uiwindow makeKeyAndVisible];
+ }
}
void
UIKit_HideWindow(_THIS, SDL_Window * window)
{
- UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
+ @autoreleasepool {
+ UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
- uiwindow.hidden = YES;
+ uiwindow.hidden = YES;
+ }
}
void
@@ -286,13 +292,17 @@ UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
void
UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{
- UIKit_UpdateWindowBorder(_this, window);
+ @autoreleasepool {
+ UIKit_UpdateWindowBorder(_this, window);
+ }
}
void
UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{
- UIKit_UpdateWindowBorder(_this, window);
+ @autoreleasepool {
+ UIKit_UpdateWindowBorder(_this, window);
+ }
}
void
@@ -300,27 +310,32 @@ UIKit_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
- if (data) {
- [data->viewcontroller release];
- [data->uiwindow release];
- SDL_free(data);
+ @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)
{
- UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
+ @autoreleasepool {
+ UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
- if (info->version.major <= SDL_MAJOR_VERSION) {
- info->subsystem = SDL_SYSWM_UIKIT;
- info->info.uikit.window = uiwindow;
- return SDL_TRUE;
- } else {
- SDL_SetError("Application not compiled with SDL %d.%d\n",
- SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
- return SDL_FALSE;
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ info->subsystem = SDL_SYSWM_UIKIT;
+ info->info.uikit.window = uiwindow;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d\n",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
}
}
@@ -333,7 +348,10 @@ SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callbac
return SDL_SetError("Invalid window or view not set");
}
- [data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam];
+ @autoreleasepool {
+ [data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam];
+ }
+
return 0;
}