InvalidOperationException

May 28, 2008 at 3:33 PM
Edited May 28, 2008 at 4:42 PM
ok, I am playing with a couple of things here and have come across a recurring exception with the RotateTransition.

If I set up a window with a listbox and a TransitionElement.  For each UIElement I create, I add a ListBoxItem to the ListBox.  The ListBoxItem has a VisualBrush of the UIElement as its content, and I store the UIElement in the Tag property of the ListBoxItem.  That way we end up with a series of small windows in the ListBox that the user can select and then we transition to the real window in the TransitionElement.

When I  select an item in the listbox, I take the tag and use it as the content for the TransitionElement.  Make sense?

Works wonderfull if I am not using the RotateTransition.  If I use the RotateTransition I get an InvalidOperationException.  DoorTransition works fine, and so do the others I have tested so far.

Thinking I might have the element in two different visual trees at the same time, I tried using a derivation of Dr. WPF's LogicalPanel (http://69.10.233.10/KB/WPF/ConceptualChildren.aspx) to hold the UIElements.  Same problem/Behavior.

ok after some testing these transitions work:

DoorTransition
ExplosionTransition
FadeAndBlurTransition
FadeTransition
FlipTransition
PageTransition
RollTransition

 

These cause the exception:

CheckerboardTransition
DiagonalWipeTransition
DotsTransition
DoubleRotateWipeTransition
FadeAndGrowTransition
HorizontalBlindsTransition
HorizontalWipeTransition
MeltTransition
RotateTransition
RotateWipeTransition
StarTransition
TranslateTransition
VerticalBlindsTransition
VerticalWipeTransition

 

Any clues?  I will let you know what I find.  I am sure it something stupid that I am doing.

Thanks again for putting this suff up here.  Up to this, I have had no issues.

Paul

May 30, 2008 at 11:42 AM




After more testing, if I dont use a visualbrush of the UIElement in my listbox of available UIElements,  all of the transitions work.  So there is something going on in those transitions that causes the update of the visualBrush to throw an InvalidOperation exception.

Hmm...
Jun 9, 2008 at 9:31 AM
I'm having exactly the same issue, I've got a listbox bound to the visuals of the content I want to show. Some of the transitions work, but most blow up (but not the explosion which is ironic)
Jun 9, 2008 at 11:33 AM

thanks, at least I know it isnt only my code. <grin>

I am pretty sure it occurs on the EndTransition, I see the transition occur, and then the exception.  More digging will be required.

pmont.


MooseTaylor wrote:
I'm having exactly the same issue, I've got a listbox bound to the visuals of the content I want to show. Some of the transitions work, but most blow up (but not the explosion which is ironic)


Coordinator
Jun 9, 2008 at 1:31 PM


pmont wrote:

thanks, at least I know it isnt only my code. <grin>

I am pretty sure it occurs on the EndTransition, I see the transition occur, and then the exception.  More digging will be required.

pmont.


MooseTaylor wrote:
I'm having exactly the same issue, I've got a listbox bound to the visuals of the content I want to show. Some of the transitions work, but most blow up (but not the explosion which is ironic)





Woah, what happened there with the quad post?

I'll be happy to take a look at it but I'm a bit booked up today. If I PM you with my e-mail address can you send me some sample code that reproduces the issue?
Jun 9, 2008 at 2:11 PM
quad?  I go for at least five.   I have no idea want went wrong, but I hope it doesnt do it again. <grin>

jaredbienz wrote:


pmont wrote:

thanks, at least I know it isnt only my code. <grin>

I am pretty sure it occurs on the EndTransition, I see the transition occur, and then the exception.  More digging will be required.

pmont.


MooseTaylor wrote:
I'm having exactly the same issue, I've got a listbox bound to the visuals of the content I want to show. Some of the transitions work, but most blow up (but not the explosion which is ironic)





Woah, what happened there with the quad post?

I'll be happy to take a look at it but I'm a bit booked up today. If I PM you with my e-mail address can you send me some sample code that reproduces the issue?


Coordinator
Jun 11, 2008 at 2:09 PM
Edited Jun 11, 2008 at 2:10 PM

I just wanted to let you guys know that I am looking into this. I literally don’t have a one hour block of free time until July 17th so I’m trying to squeeze this in between calls, etc.

What I’ve found so far is that this is due to a problem with VisualBrush. In fact, I think you might have found a bug in the framework itself. I’m trying to reproduce the issue without Transitionals in the picture, but here’s what I think happens:


Transitionals takes whatever element you have and makes a VisualBrush of it before it starts animating (Transition.cs line 146). Then we say that the brush should be cached unless the visuals size crosses a threshold (Transition.cs line 149). My guess is that the animations that work are OK because the animation they do does not cause the threshold to be crossed. The other ones cause the threshold to be crossed and the VisualBrush has to be reevaluated.


Now, this is normally not a problem, but I think it MIGHT be a problem when you have another VisualBrush attached (the one you’ve got in your ListBox). The error that gets thrown is actually a memory access exception in COM! I’d bet that this is happening when DirectX is trying to evaluate the surface that represents the VisualBrush. If you use only ONE VisualBrush (either in TransitionBox OR in your Menu) everything is OK. It’s when attach two VisualBrushes to the element that’s when we get the crash.


So, anyway, I’ve got some more research to do. I can turn off caching and see if that fixes it. Or maybe there’s an option to take a snapshot of the visual and use that instead of a VisualBrush. Of course, if it’s a video or something that updates frequently it will look funny. I’ve still got some research to do but I wanted to let you guys know where I was at.

Jun 11, 2008 at 3:26 PM


jaredbienz wrote:

I just wanted to let you guys know that I am looking into this. I literally don’t have a one hour block of free time until July 17th so I’m trying to squeeze this in between calls, etc.

What I’ve found so far is that this is due to a problem with VisualBrush. In fact, I think you might have found a bug in the framework itself. I’m trying to reproduce the issue without Transitionals in the picture, but here’s what I think happens:



You are the man.  Again thanks for taking the time with this, and for the work you have done to get Transitionals up here.

Paul
Coordinator
Jun 13, 2008 at 11:38 PM
This issue is certainly deeper than the Transitionals framework itself, though I'm having trouble replicating it in a stand-alone application. The root cause is from a fun little line of code called System.Windows.Media.MediaContext.NotifyPartitionIsZombie. After doing some research I found these related forum posts:

http://forums.msdn.microsoft.com/en/wpf/thread/f3fc5b7e-e035-4821-908c-b6c07e5c7042/
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=321955

When this error shows up it seems to do with the current graphics card drivers. (NOT a good thing to have to worry about right?)

I've reached out to Gerhard Schneider see if he'll graciously assist us, but honestly this is a bit beyond me. If Gerhard can't help I'll try and ask a broader group.
Coordinator
Jun 14, 2008 at 12:42 AM
Gerhard was VERY kind and willing to take a look. He said it will at least be later Monday before he has a chance. I'll keep you posted.
Jun 14, 2008 at 2:28 PM


jaredbienz wrote:
Gerhard was VERY kind and willing to take a look. He said it will at least be later Monday before he has a chance. I'll keep you posted.


Tell him thanks from all of us.

When one has a repeatable bug, I always try to take it to its solution.  You never know when one might be able to find it again. 

I still bet on it being a bug in something I am doing <grin>  Framework bugs are few and far between, and the last thing I would figure a bug is in.  On second thought, compiler bugs are after that. <grin>
Jun 18, 2008 at 5:56 AM
One of my users of MuvUnder Cover was getting the same error related to the System.Windows.Media.MediaContext.NotifyPartitionIsZombie call.  They already had Vista SP1 and .NET 3.5 installed so the transparency hotfix didn't apply.

Having them run the DirectX End-User Runtime Web Installer, as mentioned at http://forums.msdn.microsoft.com/en-US/wpf/thread/446f5f1c-4a0b-4479-b4ac-605d3c96d90b fixed the issue for them.  The problem for me is that my program was written against .NET 3.5 which is already a 30MB+ download depending on their OS and the DirectX End-User Runtime Web Installer is an additional 22 KB - 61.2 MB (from there site, though on my VM it was about 60MB), which means to install my program and to avoid any possibility of that error would require 90-120MB of downloads for the user...obviously something I'd like to avoid.

Is there any idea exactly what file is causing the issue and is getting updated when the DirectX End-User Runtime Web Installer is run and is there anyway we could get a hotfix for just that file, or files if it's more than one?

Thanks,

John
MuvEnum

Coordinator
Jun 22, 2008 at 3:50 PM
Thanks renzska for that info. Have any of the others in this thread tried running the latest DirectX End User Runtime installer to see if it resolves the issue for you? Obviously this is not the ideal resolution and I'm still working with the WPF team to track it down.

Both Gerhard Schneider and Brendan Clark are looking at it in their spare time. On Wednesday Brendan thought he'd found it. He thought the way the visual tree was being modified in change events firing from DisconnectedUIElementCollection were part of the problem. There were asserts there, but he later decided that wasn't the root cause. He's going to debug against checked binaries to see if he can track it further, but he didn't think the version of the DirectX runtime would matter. If we have several people that have run the new web installer and it's caused the issue to go away I'd certainly like to send that feedback on.

Finally, I'd like to point out one work-around. This problem only occurs when two circumstances are true:

  1. The actual visual is not in any visual tree until it gets shown in the transition panel.
  2. There is a VisualBrush of the visual elsewhere in the visual tree at all times.

If you change either of those then I think you can work around the issue. My first thought is can you get by with just a snapsot of the visual instead of a live VisualBrush? Not as glamerous and certainly doesn't work for video, but it's a thought.

Sorry guys, I know this isn't ideal and I know it's taking a long time to get resolved but know we've got the best people posible looking at this as they can.

Jul 1, 2008 at 8:19 PM
Jared,

Any updates?  And to answer the above question, I have not installed the DirectX End User Runtime on the systems I have access to.

Again, thanks for the effort, and tell the other guys working on it thanks too.
Paul
Coordinator
Jul 1, 2008 at 9:30 PM

Well, the good news is that I have an update. The bad news is that it doesn't resolve much. I don't want to post Brendens e-mail verbatum, but I will relay the key points.

 

“I’ve verified that the DX runtime has no impact for me. … It seems like there is definitely a bug in the framework, and the bad news is that we closed up shop on 3.5 SP1 a couple weeks ago so there won’t be a fix until the next release at minimum.  I’ll open a bug on the issue so that we can track it.”

 

Without going into too much detail at this point Benden believes there is a timing issue between the managed layer and the unmanaged DirectX. Timing issues could explain why new drivers or the new DX installer seems to fix things for some people. He goes on:

 

“I have one idea for a workaround so far. The transitions seem to work fine if you use only VisualBrushes as the content of the TransitionElement during the transition.  As you stated on your forum post, the issue only occurs when you have a VisualBrush of the visual rendering somewhere, the visual has no parent Visual, and then you set the TransitionElement.Content to that visual.  I changed the code in TxnPanel.cs :: OnListBoxItemSelected to something like this:

                Rectangle rect = new Rectangle();

                rect.Height = v.Element.RenderSize.Height;

                rect.Width = v.Element.RenderSize.Width;

                rect.Fill = v.vBrush;

                te.Content = rect;

However, with only a VisualBrush there you won’t get things like hit-testing, which I’m sure you’d want.  You could work around that by then using the TransitionEnded callback so that TxnPanel or any other consumer can swap in and out the TransitionElement and the real content, i.e. detect a change -> swap old content and TE -> set TE.content to new content -> on callback swap TE and new content.  That way hit-testing and input would be live at any point, except during the transition. …”

 

Brenden did say he planned to work with others on his team who had been out to try and find a better work-around.

 

I’m going to look more into his suggestions but I want to be completely honest that I might not have any time to seriously look at it until the 18<SUP>th</SUP>. I’ve got some time blocked off on my calendar then.

 

If any of you have a chance to look at this in the mean time and have your own suggestions to make, please do so. This may be as simple as having the content always parented by the TxnPanel or may be as complex as swapping things in and out of the view. I don’t personally feel that hit testing is important during the transition (of course it is before and after). If anyone feels that proper hit testing is important during the transition please let me know as that might have a big impact on the bug fix. Please cite examples as to when you’d need this functionality, and thanks.

 

Regards,

 

Jared

Jul 2, 2008 at 12:33 AM
Thanks for the update.

Your suggestion of using a snapshot is fine for what I am doing.  I just wanted to make sure that a reproducible example of the bug is not lost by getting around the problem.  It is always better to drive to the actual problem and fix it then to do a workaround and lose reproducibility of the error.

As always the intent is to make the product the best that it can be.  Again, tell them thanks, and if it really is a framework bug, make sure you get an honorable mention for it. <grin>

Paul
Coordinator
Jul 19, 2008 at 3:16 AM

I’m pleased to say I believe this issue has been resolved. As many of you have experienced before, the fix turned out to be beautifully simple but it took hours of refactoring, debugging and a little luck to find.

The real steps to failure are:

1.       Create any piece of UI content

2.       Create a VisualBrush

3.       Set VisualBrush.Visual to the content created in step #1

4.       Display the VisualBrush somewhere in the visual tree (for example, use it as the Fill for a rectangle that’s displayed in a grid)

5.       Create a ContentPresenter

6.       Set the ContentPresenter.Content to the same content created in step #1 (now the ContentPresenter and VisualBrush are both pointing at the same content)

7.       Add the ContentPresenter somewhere in the visual tree (for example, add it to the same grid as the rectangle mentioned above)

8.       Run the program and you should see two copies of the same content created in step #1 (the actual content displayed through the ContentPresenter and a visual ‘copy’ represented by the VisualBrush)

9.       Now remove the ContentPresenter from the visual tree while the application is running (for example, in a button click handler do grid.Children.Remove(presenter) )

10.   The failure will occur.

This failure will occur even if you immediately re-add the presenter to the grid as soon as you’ve removed it. VisualBrush, it seems, cannot handle its visual being associated with a ContentPresenter that’s been attached and then detached from the visual tree.

VisualBrush has a problem showing content that’s also in a non-rooted ContentPresenter, but VisualBrush seems just fine with representing content that’s not connected to anything at all. I realize that statement can be a bit confusing, but basically the failure is due to the content being simultaneously hosted in a ContentPresenter that get’s disconnected from the tree.

So the fix appears to be simple: Disassociate the content from the ContentPresenter before removing the ContentPresenter from the visual tree. Once the two are disconnected, the ContentPresenter can be moved around and re-parented all you want. Just make sure the ContentPresenter is back in the visual tree somewhere before you associate the content with it again.

This workaround has been committed to source control but I’m not going to do a binary release until I address a few more issues. Please try it out if you have time and let me know if it works for you.

Regards,

Jared Bienz

Coordinator
Jul 19, 2008 at 5:36 AM
Just a note that I tried to follow these steps outside of Transitionals and couldn't reproduce the failure. Deffinately some strange timing issues going on there but it appears pretty solid now. The failing sample pmont sent me doesn't fail with any of the originally failing transitions.

1.1 has been relased including binaries. Check the releases tab and let me know how things work out for you.
Jul 19, 2008 at 12:15 PM


jaredbienz wrote:
Just a note that I tried to follow these steps outside of Transitionals and couldn't reproduce the failure. Deffinately some strange timing issues going on there but it appears pretty solid now. The failing sample pmont sent me doesn't fail with any of the originally failing transitions.

1.1 has been relased including binaries. Check the releases tab and let me know how things work out for you.


Good job,

I will download the new version and check it out.    ( See, when you are working on this, instead of Views, the progress you can make!  <grin> )
Jul 19, 2008 at 12:37 PM


jaredbienz wrote:
Just a note that I tried to follow these steps outside of Transitionals and couldn't reproduce the failure. Deffinately some strange timing issues going on there but it appears pretty solid now. The failing sample pmont sent me doesn't fail with any of the originally failing transitions.

1.1 has been relased including binaries. Check the releases tab and let me know how things work out for you.


Ran through my test and everything works great! 

Glad it got fixed.  So now if I understand this correctly, there is a bug in the VisualBrush WRT its ability to handle being related to content in a non-rooted ContentPresenter.  That has not been fixed, what has been done is a work around in the Transitionals code to avoid the issue.  Not that that is a bad thing, because the new way is probably better than the old way. 

I assume the framework team now has the bug on their list for a fix in a future release of the framework?  I am sure that others are having the issue without the use of Transitionals.

I will do some more playing and see what other neat things you have come up with.

Thanks again for the effort and time you have put into this.  ( Now if you can get Views running on WPF, or at least get the VE people to release a WPF ( not silverlight ) VE control, I will be a happy man. My discusions with the MS reps for the company I work for dont seem to be yeilding short term fruit on that front. )

Paul
Jul 19, 2008 at 3:06 PM
Edited Jul 19, 2008 at 3:23 PM


 
Just a quick note on an anomoly I am seeeing now that I wasnt seeing before.

I have customized a tab control to use Transitionals.  That Tab Control I am using as a region in a prism test app.  I am adding views to that region through a configuration loaded module.  The first active view shows fine, when I transition to the next view by clicking on the tab, the new view does not show during the transition, but shows after the transition is complete.  This does not occur on transitions to the third view in the region, nor transitions back to the second view.  Its a one time deal.

None of the views are visible until the transition.  They are just added to the region and show as tab items.  No visual brushes are being used in this app. <grin>

I am using the Rotation transition for this.  It does not happen on the Translate Transition.  If you want the code let me know.
Coordinator
Jul 24, 2008 at 3:42 AM
I've seen this now too but don't have an answer yet. Can you create an issue in the issue tracker?