Crash occurs for some images

I add a System.Windows.Controls.Image to a Canvas in a window.

For some images i get an exception with the following stack trace.

" at System.Windows.Media.MediaContext.NotifyPartitionIsZombie(Int32 failureCode)\r\n at System.Windows.Media.MediaContext.NotifyChannelMessage()\r\n at System.Windows.Media.MediaContext.CompleteRender()\r\n at System.Windows.Interop.HwndTarget.OnResize()\r\n at System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)\r\n at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)\r\n at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)\r\n at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)\r\n at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)\r\n at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)\r\n at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)\r\n at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at MS.Win32.UnsafeNativeMethods.SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)\r\n at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)\r\n at System.Windows.Window.CreateSourceWindowImpl()\r\n at System.Windows.Window.SafeCreateWindow()\r\n at System.Windows.Window.ShowHelper(Object booleanBox)\r\n at System.Windows.Window.Show()\r\n at System.Windows.Window.ShowDialog()\r\n at Teradion.DIMMainWindow.ResourcePreview(Uri uri) in F:\\StandardOnly\\Teradion\\MainWindow.xaml.cs:line 18285"

Please help.

Thanks in advance.

Sakthi Sai Saranyan

[2628 byte] By [SakthiSaiSaranyan] at [2008-1-5]
# 1
Can you make sure that you have the latest drivers for your video card?
RobertA.Wlodarczyk-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
I'm having a very similar issue: inside a Canvas object, I'm creating a number of Image objects. The following code produces a nasty crash which the debugger won't let me catch -- even though I'm running the program from the VS2005, in Debug mode.

Uri uri = new Uri("pack://application:,,/Images/Circle.png");
BitmapImage bitmap = new BitmapImage(uri);
Image img = new Image();
img.Source = bitmap;
this.Children.Add(img);

If I comment out either of the last two lines, the crash goes away. (And so do the images, of course.)

This phenomenon only occurs on one of my machines: a dual-CPU machine with an nVidia 4500x2 card. The drivers are the latest version: 91.85. I've also run the application on a Vista machine and on an XP laptop, and it works fine.

Any help greatly appreciated.

sandover at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
any particular images or certain number that you've noticed it has the most problems with?
WPCoder at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4
I tried it with a different image in the project (also a .png) -- it didn't seem to make any difference. I'll try a jpg and post the results. I'll also try a relative URI, just for the heck of it.

sandover at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5
I was wondering if there might be some issue with the Uri, so I tried relative. I also tried a jpg instead of a png. The result is the same. It's a strange crash -- the debugger simply doesn't catch it. The traditional "Debug/Send/Don't Send" dialog comes up. If you click "Debug", it offers to open a copy of Visual Studio. If you do this, however, it will eventually refuse, because "Unable to attach to the crashing process. A debugger is already attached."

I've written the minimal version of the program that will reproduce this behavior. Here it is:

public class MainWindow : Window
{
Canvas mainCanvas;

[STAThread]
public static void Main()
{
Application app = new Application();
app.Run( new MainWindow() );
}
public MainWindow()
{
// Create canvas
mainCanvas = new Canvas();
Content = mainCanvas;
mainCanvas.Width = Width;
mainCanvas.Height = Height;

Uri uri = new Uri("diamondgraph.jpg", UriKind.Relative);
BitmapImage bitmap = new BitmapImage(uri);
Image img = new Image();
img.Source = bitmap;
mainCanvas.Children.Add(img);
Canvas.SetLeft(img, 0);
Canvas.SetTop(img, 0);
img.Width = 300;
img.Height = 300;
}
}

sandover at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6
You would normally want to call InitializeComponent prior to your code in the MainWindow's constructor. (If you don't call it, things aren't initialized properly -- like the mainCanvas.Width property gets set to Auto rather than the actual width of the Window.

I'm sure you'll hate to hear this, but both with and without the call to InitializeComponent, it works fine for me with the jpg I tried. I used an absolute path in my test.

WPCoder at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 7

I figured out how to solve this problem, though I'm still mystified as to the underlying cause. What I did was to I install the "DirectX End-User Runtime Web Installer" on the machines where the application would not run. The application just worked after that.

Note that this is different from the "DirectX End-User Runtime" download package which is the generally first hit to come up on Google (and on MSDN). That package (version number 9.0c) has a release date in 2004. The Web Installer package has a release date of 6/12/2007, and a sort of "version number" of "9.19.1005" (Have the DirectX version number people been drinking at work?). This kind of update has never been offered through Windows Update, as far as I know. It's just something I dug up and decided to try.

So I had run the test WPF application on various machines, under XP and Vista, with graphics cards (nVidia Quadro 4500x2, nVidia Quadro 3000, nVidia Quadro 3400, laptop chipset, etc.) and driver versions (91.36, 91.85, etc.). .NET 3.0 was installed on all the machines. There just didn't seem to be any reliable predictor of when the application would fail.

But the Web Installer fixed the crashing issue on every machine.

sandover at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified