【发布时间】:2014-06-20 04:42:05
【问题描述】:
这只是从用户那里报告的。该程序的这一部分已经在野外进行了广泛的测试和使用,并且在一段时间内没有改变。似乎它对她有用,只是最近才开始失败。由于图像来自资源,因此不需要处置。在我的测试中(并通过检查代码),这应该总是发生在 UI 线程上,所以我最好的猜测是程序已经以某种方式损坏,导致资源中的图像实际上是无效的。这是否有意义,或者有更合理的解释。这是调用堆栈:
Msg: Parameter is not valid.
Source: System.Drawing
Assembly: System.Drawing, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
Stack: at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.PictureBox.GetPreferredSizeCore(Size
proposedSize)
at System.Windows.Forms.Control.GetPreferredSize(Size proposedSize)
at
System.Windows.Forms.Layout.TableLayout.GetElementSize(IArrangedElement
element, Size proposedConstraints)
at System.Windows.Forms.Layout.TableLayout.InflateColumns(ContainerInfo
containerInfo, Size proposedConstraints, Boolean measureOnly)
at System.Windows.Forms.Layout.TableLayout.ApplyStyles(ContainerInfo
containerInfo, Size proposedConstraints, Boolean measureOnly)
at System.Windows.Forms.Layout.TableLayout.LayoutCore(IArrangedElement
container, LayoutEventArgs args)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container,
LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs
levent)
at System.Windows.Forms.TableLayoutPanel.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement
affectedElement, String affectedProperty)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement
affectedElement, String affectedProperty)
at System.Windows.Forms.PictureBox.InstallNewImage(Image value,
ImageInstallationType installationType)
at System.Windows.Forms.PictureBox.set_Image(Image value)
at SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.UpdateDisplay()
at
SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.BeginRecording(TimeRange
timeRangeOfSourceBeingAnnotated)
at
SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.HandleRecordAnnotationMouseDown(Object
sender, MouseEventArgs e)
at
SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.OnLowLevelKeyDown(Keys
key)
at
SayMore.UI.LowLevelControls.MonitorKeyPressDlg.PreFilterMessage(Message& m)
at System.Windows.Forms.Application.ThreadContext.ProcessFilters(MSG&
msg, Boolean& modified)
at
System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at
System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at SayMore.Model.Files.ComponentFile.RecordAnnotations(Form frm,
AudioRecordingType annotationType)
at
SayMore.Transcription.UI.TextAnnotationEditor.<>c_DisplayClassb.<HandleRecordedAnnotationButtonClick>b_a()
at
SayMore.Transcription.UI.TextAnnotationEditor.ShowSegmentationDialog(Action
showDialog)
at
SayMore.Transcription.UI.TextAnnotationEditor.HandleRecordedAnnotationButtonClick(Object
sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
这是我们代码中设置图像的方法:
protected override void UpdateDisplay()
{
_recDeviceIndicator.UpdateDisplay();
_labelListenButton.Image = (_waveControl.IsPlaying && _playingBackUsingHoldDownButton ?
Resources.ListenToOriginalRecordingDown : Resources.ListenToOriginalRecording);
_labelRecordButton.Image = (ViewModel.GetIsRecording() ?
Resources.RecordingOralAnnotationInProgress : Resources.RecordOralAnnotation);
_labelListenButton.Enabled = !ViewModel.GetIsRecording() &&
(ViewModel.CurrentUnannotatedSegment != null || !ViewModel.GetIsFullyAnnotated());
_labelRecordButton.Enabled = (ViewModel.GetSelectedSegmentIsLongEnough() &&
_userHasListenedToSelectedSegment &&
AudioUtils.GetCanRecordAudio(true) &&
!_waveControl.IsPlaying && !ViewModel.GetIsAnnotationPlaying());
_labelListenHint.Visible = _spaceBarMode == SpaceBarMode.Listen && _labelListenButton.Enabled;
_labelRecordHint.Visible = _spaceBarMode == SpaceBarMode.Record && _labelRecordButton.Enabled && !_reRecording && _recordingErrorMessage == null;
if (_spaceBarMode == SpaceBarMode.Done && _recordingErrorMessage == null)
{
if (!_labelFinishedHint.Visible)
{
_pictureIcon.Image = Resources.Green_check;
_labelFinishedHint.Visible = true;
_tableLayoutButtons.Controls.Add(_labelFinishedHint, 1, 0);
_tableLayoutButtons.SetRowSpan(_labelFinishedHint, 3);
AcceptButton = _buttonOK;
}
}
else
{
UdateErrorMessageDisplay();
if (_labelErrorInfo.Visible)
{
_pictureIcon.Image = Resources.Information_red;
if (_labelFinishedHint.Visible)
{
_labelFinishedHint.Visible = false;
_tableLayoutButtons.Controls.Remove(_labelFinishedHint);
}
_labelRecordHint.Visible = false;
}
else
{
_pictureIcon.Image = Resources.Information_blue;
}
float percentage = (_labelErrorInfo.Visible) ? 50 : 100;
_tableLayoutButtons.RowStyles[0].Height = (_labelErrorInfo.Visible) ? percentage : 0;
_tableLayoutButtons.RowStyles[1].Height = (_labelListenHint.Visible) ? percentage : 0;
_tableLayoutButtons.RowStyles[2].Height = (_labelRecordHint.Visible) ? percentage : 0;
}
base.UpdateDisplay();
}
我不确定设置 Image 的哪个调用导致了异常,但根据上下文,我怀疑是 _labelRecordButton.Image 设置为 Resources.RecordingOralAnnotationInProgress。关键是,在每种情况下,图像都只是来自资源,因此它应该始终有效。
【问题讨论】:
-
刚刚发现类似错误"Parameter Not Valid" in line `decoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);` 重复调用包含该行的函数(针对不同的图片) 并且在可变数量的调用后会发生故障,但对于较大的图像会更快,这意味着内存问题。但是,使用任务管理器进行监控显示重复调用不会系统性地增加内存使用量。
-
删除了对 JpegBitmapDecoder 的调用,但在从使用资源监视器检查的文件创建位图时仍然偶尔会遇到相同的错误,当崩溃发生时,内存分配中没有显示异常的功能。当应用程序(例如打开许多选项卡的浏览器)提交大量内存时,以及应用程序在提交更多内存时处理更大的图像时,崩溃会更频繁。所以它闻起来像是内存问题,但诊断不支持这一点。
标签: image embedded-resource system.drawing argumentexception