From 0be378605d656525d8fbd909367a45e0f47311f8 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 13 Jul 2012 15:14:31 +0200 Subject: [PATCH] Vocaluxe no longer crashes if no webcam was found Webcam related slides and preview are no longer shown in video options screen if no webcam was found --- Vocaluxe/Lib/Webcam/CAForgeNet.cs | 2 ++ Vocaluxe/Screens/CScreenOptionsVideo.cs | 44 ++++++++++++++----------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 3e798c37..1dd9a97f 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -135,6 +135,8 @@ namespace Vocaluxe.Lib.Webcam if (_WebcamDevices == null) return false; + if (_WebcamDevices.Count < 1) + return false; //No MonikerString found, try first webcam if (Config.MonikerString == String.Empty) diff --git a/Vocaluxe/Screens/CScreenOptionsVideo.cs b/Vocaluxe/Screens/CScreenOptionsVideo.cs index fb4f3e4f..3e15a258 100644 --- a/Vocaluxe/Screens/CScreenOptionsVideo.cs +++ b/Vocaluxe/Screens/CScreenOptionsVideo.cs @@ -167,30 +167,34 @@ namespace Vocaluxe.Screens if (devices != null) { - _DeviceNr = 0; - _CapabilityNr = 0; - GetFirstConfiguredWebcamDevice(ref _DeviceNr, ref _CapabilityNr); - - foreach (SWebcamDevice d in devices) + if (devices.Length > 0) { - SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].AddValue(d.Name); - } - SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection = _DeviceNr; + _DeviceNr = 0; + _CapabilityNr = 0; + GetFirstConfiguredWebcamDevice(ref _DeviceNr, ref _CapabilityNr); - foreach (SCapabilities c in devices[_DeviceNr].Capabilities) - { - SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].AddValue(c.Width.ToString() + " x " + c.Height.ToString() + " @ " + c.Framerate.ToString() + " FPS "); + foreach (SWebcamDevice d in devices) + { + SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].AddValue(d.Name); + } + SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection = _DeviceNr; + + foreach (SCapabilities c in devices[_DeviceNr].Capabilities) + { + SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].AddValue(c.Width.ToString() + " x " + c.Height.ToString() + " @ " + c.Framerate.ToString() + " FPS "); + } + _Config.MonikerString = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString; + _Config.Width = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width; + _Config.Height = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height; + _Config.Framerate = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate; + CWebcam.Close(); + CWebcam.Select(CConfig.WebcamConfig); + CWebcam.Start(); } - _Config.MonikerString = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString; - _Config.Width = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width; - _Config.Height = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height; - _Config.Framerate = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate; - CWebcam.Close(); - CWebcam.Select(CConfig.WebcamConfig); - CWebcam.Start(); } - SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Visible = (devices != null); - SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Visible = (devices != null); + SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Visible = (devices != null && devices.Length > 0); + SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Visible = (devices != null && devices.Length > 0); + Statics[htStatics(StaticWebcamOutput)].Visible = (devices != null && devices.Length > 0); } private void SaveConfig()