Example #1
0
    private void LoadSample(int sampleIndex)
    {
      EndSample();
      CloseWindows();

      var type = _samples[sampleIndex];

      // Use the service container to create an instance of the sample. The service
      // container will automatically provide the sample constructor with the necessary
      // arguments.
      try
      {
        _sample = (Sample)_services.CreateInstance(type);
      }
      catch (TargetInvocationException exception)
      {
        // Samples are created using reflection. If the sample constructor throws an exception,
        // we land here.

        // Throw inner exception, which is more useful.
        throw exception.InnerException;

        // To break at the actual code line which caused the exception, you can tell the Visual 
        // studio debugger to break at "first chance" exceptions:
        // Open the exception settings in Visual Studio using the menu
        //   Debug > Windows > Exception Settings (VS 2015)
        // or 
        //   Debug > Exceptions... (VS 2013 and older)
        // and check the check box next to "Common Language Runtime Exceptions".
        // If you run the game again, then the debugger should break where the
        // inner exception is created and not on this line.
      }

      _sampleIndex = sampleIndex;
      _nextSampleIndex = sampleIndex;
      _game.Components.Add(_sample);

      UpdateHelp();

      if (_optionsTabControl.Items.Count > 1)
        _optionsTabControl.SelectedIndex = _optionsTabControl.Items.Count - 1;
    }
Example #2
0
    private void EndSample()
    {
      if (_sample != null)
      {
        _game.Components.Remove(_sample);
        _sample.Dispose();
        _sample = null;

        ResetOptions();

        Profiler.ClearAll();
        ResourcePool.ClearAll();
        GC.Collect();
      }
    }
Example #3
0
        TreePosition AddSample(TreePosition category, string name, Type sampleType)
        {
            Sample sample = new Sample (category, name, sampleType);

            TreeNavigator node = store.AddNode (category);
            TreeNavigator nameNavigator = node.SetValue (nameCol, name);
            TreeNavigator iconNavigator = nameNavigator.SetValue (iconCol, icon);
            TreeNavigator sampleNavigator = iconNavigator.SetValue (sampleCol, sample);
            return sampleNavigator.CurrentPosition;
        }