-
Notifications
You must be signed in to change notification settings - Fork 668
Fix MAGN-9568 Crash in preview control #6240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| return cachedValue; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad this is now gone, as the warning comment indicated this is a dangerous method. Wondering what's happening to the test cases that use it though... may have been removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In test cases, replace it with AssertPreviewValue(). I guess this method was added before AssertPreviewValue()? :-)
|
Hi @aosyatnik, we took this on because both @ke-yu and myself worked on the initial preview control, and us being in the same office we could discuss everything in details. Having the fix discussed, developed, and tested within hours will allow greater leeway, should anything unexpected shows up. Thanks anyway for your initial fixes! Hey @ke-yu, few comments and LGTM, time to get a build for testing! Thanks also for helping out with this! |
|
Ready! |
Fix MAGN-9568 Crash in preview control
|
@ke-yu I think we can get rid of |
|
@aparajit-pratap sure, I forget to remove it. Will do. |
|
Good point, @aparajit-pratap! 👍 Also @ke-yu, we need this cross-merged to |
Purpose
Fix MAGN-9568 Crash in preview control
There are two issues, both related to outdated mirror data that used in preview control to query the node value from the DesignScript virtual machine.
Updating a graph will update mirror data in all executed UI nodes. Ideally, the following preview operation will get the latest mirror data to display value. But because updating graph (
UpdateGraphAsyncTask), querying mirror data (QueryMirrorDataAsyncTask) and displaying preview value (wrapped inDelegateBasedAsyncTask) are all asynchronous operations, and their creation is not necessarily in scheduler thread, their execution order is not guaranteed and the outdated mirror data will be used and cause crash.The first issue is
DelegateBasedAsyncTaskis scheduled beforeQueryMirrorDataAsyncTask.In this case,
UpdateGraphAsyncTaskhas been executed and node's value has been updated. Now aDelegateBasedAsyncTaskis created and put in scheduler thread (because of previewing operation on the UI thread). It will be executed immediately becauseQueryMirrorDataAsyncTaskhas not been scheduled yet:NodeModel.CachedValuehas not been updated yet, but the value of node has been changed, soNodeModel.CachedValuebecomes invalid.There are three ways to fix this case:
NodeModel.CachedValueto some invalid state. InDelegateBasedAsyncTaskwe will check if mirror data is invalid or not, and display "..." in the preview control accordingly. Mirror data will finally be updated inQueryMirrorDataAsyncTask. But introducing more states will make the code be harder to maintain.MirrorDatais a snapshot of value, we could add the other kind of mirror data which always reflects current value. ButMirrorDatais widely used now, making this change will incur too many other changes. Besides, always querying value from the engine would be a potential performance issue.UpdateGraphAysncTaskis executed. Firstly, it is a trivial change; secondly, if we can ensure all these operations happen in scheduler thread,DelegateBasedAsyncTaskwould never get a change to kick in and get executed. This PR uses this option.Related change:
NodeModel.RequestValueUpdateAsync()is updated to synchronousNodeModel.RequestValueUpdate().The second issue is,
PreviewControlholds a cached of mirror data (PreviewControl.mirrordata), thismirrordatawill only be updated afterUpdateGraphAsyncTaskis scheduled, but before that,DelegateBasedAsyncTaskmay be scheduled already:Again, invalid mirror data is used.
As
PreviewControlknows aboutNodeModel, it can always get the latest mirror data fromNodeModel. So this PR removesPreviewControl.mirrorData.Declarations
Check these if you believe they are true
*.resxfilesReviewers
@benglin : @riteshchandawar has helped to do some play testing.
@aosyatnik please help to review preview control part in case I miss something, and sorry for stealing the task from you... :-)