Skip to content

Conversation

@angelowang
Copy link
Contributor

@angelowang angelowang commented Sep 20, 2019

Please Note:

  1. Before submitting the PR, please review How to Contribute to Dynamo
  2. Dynamo Team will meet 1x a month to review PRs found on Github (Issues will be handled separately)
  3. PRs will be reviewed from oldest to newest
  4. If a reviewed PR requires changes by the owner, the owner of the PR has 30 days to respond. If the PR has seen no activity by the next session, it will be either closed by the team or depending on its utility will be taken over by someone on the team
  5. PRs should use either Dynamo's default PR template or one of these other template options in order to be considered for review.
  6. PRs that do not have one of the Dynamo PR templates completely filled out with all declarations satisfied will not be reviewed by the Dynamo team.
  7. PRs made to the DynamoRevit repo will need to be cherry-picked into all the DynamoRevit Release branches that Dynamo supports. Contributors will be responsible for cherry-picking their reviewed commits to the other branches after a LGTM label is added to the PR.

Purpose

Fix crash when opening second script in French C3D

Steps to reproduce:

  • Launch Dynamo in French OS and French Civil 3D.
  • Open from Help menu: Help>Samples>Core>Core_ListAtLevel.dyn
  • Without close the dyn, open from Help menu: Help>Samples>Core>Core_ListLacing.dyn.
  • Exception dialog comes and C3D will crash.

The exception arises when converting 1.0 to double under fr-FR culture,
in GroupFontSizeToEditorEnabledConverter.Convert() on values[0].

Questions:

  • Where does this 1.0 come from?
    It is from AnnotationView.xaml, where FallbackValue of the Visibility
    property is set to 1.0. When we switch from first dyn to the second, the
    current workspace will be removed, triggered WPF binding updates.

  • Why it doesn't crash when we do the same operation in DynamoSandbox?
    WPF actually doesn't follow CurrentCulture or CurrentUICulture
    when resolving the binding (https://weblog.west-wind.com/posts/2009/Jun/14/WPF-Bindings-and-CurrentCulture-Formattings.
    So by default, the culture passed to the Convert method is always en-US.
    So it is OK.

  • How to reproduce with DynamoSandbox?
    You have to manually add several lines of code to DynamoSandbox entry fuction, it will crash
    although no exception dialog (interestingly, it pops up IE on my side).

CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
  • Why does Civil 3D have fr-FR culture?
    People buying Civil 3D will get Map 3D for free. The Map 3D dll, Autodesk.Map.IM.Loader.dll,
    will override the Culture to be used by all WPF bindings, with the very similar code as above.
    When I rename it, the crash goes away.

  • So how to fix?
    At this stage, the safest fix would be simply changing 1.0 to 1.
    Later we should evaluate whether we really need to simply use the InvariantCulture
    in all our binding coverters. We have unit tests for those converters, so also
    need to remove/change them if decided to go that way.
    Another way, we might should catch all the exception and Converter.ToDouble() and use invariant culture if failed..

Declarations

Check these if you believe they are true

  • The code base is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning, and are documented in the API Changes document.

Reviewers

Michael Kirschner
Aaran Tang

FYIs

Steps to reproduce:
- Launch Dynamo in French OS and French Civil 3D.
- Open from `Help` menu: `Help>Samples>Core>Core_ListAtLevel.dyn`
- Without close the dyn, open from `Help` menu: `Help>Samples>Core>Core_ListLacing.dyn`.
- Exception dialog comes and C3D will crash.

The exception arises when converting `1.0` to double under `fr-FR` culture,
in `GroupFontSizeToEditorEnabledConverter.Convert()` on `values[0]`.

Questions:
- Where does this `1.0` come from?
- It is from `AnnotationView.xaml`, where `FallbackValue` of the `Visibility`
property is set to `1.0`. When we switch from first dyn to the second, the
current workspace will be removed, triggered WPF binding updates.

- Why it doesn't crash when we do the same operation in DynamoSandbox?
- WPF actually doesn't follow `CurrentCulture` or `CurrentUICulture`
when resolving the binding (https://weblog.west-wind.com/posts/2009/Jun/14/WPF-Bindings-and-CurrentCulture-Formattings.
  So by default, the `culture` passed to the `Convert` method is always `en-US`.
  So it is OK.

- How to reproduce with DynamoSandbox?
- You have to manually add several lines of code to DynamoCore entry fuction.
```
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
```

- Why does Civil 3D have `fr-FR` culture?
- People buying Civil 3D will get Map 3D for free. The Map 3D dll, `Autodesk.Map.IM.Loader.dll`,
  will override the Culture to be used by all WPF bindings, with the very similar code as above.
  When I rename it, the crash goes away.

- So how to fix?
- At this stage, the safest fix would be simply changing `1.0` to `1`.
  Later we should evaluate whether we really need to simply use the InvariantCulture
  in all our binding coverters. We have unit tests for those converters, so also
  need to remove/change them if decided to go that way.
@mjkkirschner
Copy link
Member

Thanks for the write up @angelowang - I think I understand whats happening now. This will need to end up getting merged to a different branch, and like you mentioned above I think we should add some try/catch logic, and a test for this situation. (we can try to set the localization to FR just for the test, and then set it back after).

We'll make a PR.

@angelowang angelowang changed the base branch from RC2.4.0_master to RC2.4.1_master September 23, 2019 02:39
@angelowang angelowang closed this Sep 23, 2019
@angelowang angelowang deleted the RC2.4.0_master branch September 26, 2019 07:43
@horatiubota horatiubota added the error/warning/crash Issues mentioning a Dynamo error, warning or crash message label Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error/warning/crash Issues mentioning a Dynamo error, warning or crash message

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants