Example #1
0
        private void InitializeGameComponents()
        {
            // There is no autorelease pool when this method is called because it will be called from a background thread
            // It's important to create one or you will leak objects
            using (NSAutoreleasePool pool = new NSAutoreleasePool()) {
                // Leave the following code there just in case there are problems
                // with the intialization hack.
                //foreach (GameComponent gc in _gameComponentCollection) {
                foreach (IGameComponent gc in _gameComponentsToInitialize)
                {
                    // We may be drawing on a secondary thread through the display link or timer thread.
                    // Add a mutex around to avoid the threads accessing the context simultaneously
                    _view.OpenGLContext.CGLContext.Lock();

                    // set our current context
                    _view.MakeCurrent();

                    gc.Initialize();

                    // now unlock it
                    _view.OpenGLContext.CGLContext.Unlock();
                    _gameComponentsToInitialize.Remove(gc);
                }
            }
        }
Example #2
0
        private void InitializeGameComponents()
        {
            // There is no autorelease pool when this method is called because it will be called from a background thread
            // It's important to create one or you will leak objects
            using (NSAutoreleasePool pool = new NSAutoreleasePool()) {
                // Leave the following code there just in case there are problems
                // with the intialization hack.

                //foreach (GameComponent gc in _gameComponentCollection) {
                //foreach (IGameComponent gc in _gameComponentsToInitialize) {
//				foreach (IGameComponent gc in _gameComponentCollection) {
//					// We may be drawing on a secondary thread through the display link or timer thread.
//					// Add a mutex around to avoid the threads accessing the context simultaneously
//					_view.OpenGLContext.CGLContext.Lock ();
//
//					// set our current context
//					_view.MakeCurrent ();
//
//					gc.Initialize ();
//
//					// now unlock it
//					_view.OpenGLContext.CGLContext.Unlock ();
//					_gameComponentsToInitialize.Remove(gc);
//				}

                // Changed from foreach to for loop in case the GameComponents's Update method
                //   modifies the component collection.  With a foreach it causes an error:
                //  "Collection was modified; enumeration operation may not execute."
                //  .Net 4.0 I thought got around this but in Mono 2.10.2 we still get this error.
                for (int x = 0; x < _gameComponentCollection.Count; x++)
                {
                    var gc = (GameComponent)_gameComponentCollection[x];
                    // We may be drawing on a secondary thread through the display link or timer thread.
                    // Add a mutex around to avoid the threads accessing the context simultaneously
                    _gameWindow.OpenGLContext.CGLContext.Lock();

                    // set our current context
                    _gameWindow.MakeCurrent();

                    gc.Initialize();

                    // now unlock it
                    _gameWindow.OpenGLContext.CGLContext.Unlock();
                    _gameComponentsToInitialize.Remove(gc);
                }
            }
        }