cinder/Cinder — pull request #479 by pizthewiz (2014-08-07 04:09:17+00:00)
Title: Avoid out of bounds array access after window closed

A window-less Cinder application can be very useful and yet it isn't obvious how best it should be created. Options are not available on `Window::Format` or `Settings` to prevent the creation in `App::prepareSettings(Settings* settings)`, instead one must call `close()` on it. While `hide()` will conceal the window, the draw loop is still executed.

If `close()` is called during `App::setup()`, an error is logged to the console after it executes:
```sh
2014-08-06 11:37:58.747 Process[77904:996154] *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
```

The error originates from `-[AppImplCocoaBasic applicationDidFinishLaunching:]` [line 101](https://github.com/cinder/Cinder/blob/dev/src/cinder/app/AppImplCocoaBasic.mm#L101):
```Objective-C
// make the first window the active window
[self setActiveWindow:[mWindows objectAtIndex:0]];
```

When the window is closed, `mWindows` is empty. It would be awesome to use the concise `-[NSArray firstObject]`, but while it is available when targeting 10.6, the updated SDK wasn't available until Xcode 5+, so it cannot be built on 10.6 which the the minimum requirement of 0.8.6.