Skip to content

Conversation

@albtaeler
Copy link
Contributor

…ntationSource (#1798)

Fixes #1798 .

Checklist

  • I have included examples or tests
  • I have updated the change log
  • I am listed in the CONTRIBUTORS file
  • I have cleaned up the commit history (use rebase and squash)

Changes proposed in this pull request:

  • Return/use the default values if the PresentationSource or the ancestor visual is null:

@oxyplot/admins

@VisualMelon
Copy link
Contributor

Thanks for putting this together. I can't take a proper look now, but hopefully I'll be able to get back to you on this in the next few days.

@albtaeler
Copy link
Contributor Author

I force pushed a version with the fix (default values if the ancestor visual is null) for the canvas renderer, too.

@albtaeler
Copy link
Contributor Author

Another NullReferenceException appeared during tests of our application with the latest Oxyplot version.
I had to add this check in Plotview.cs SkElement_PaintSurface().

        private void SkElement_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            if (this.plotPresenter == null || this.renderContext == null)
            {
                return;
            }

Hopefully you @VisualMelon or another maintainer will have time to review it soon.

Copy link
Contributor

@VisualMelon VisualMelon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good. Some duplication in #1820; I suggest we merge this and then work out if there is anything in #1820 that is missing.

@VisualMelon
Copy link
Contributor

VisualMelon commented Dec 24, 2021

Merged now so that we can look at #1820 properly, and because this was checked with the WPF and has 3 issues requesting the fix.

Thanks again @albtaeler for this and #1797

protected override double UpdateDpi()
{
var scale = base.UpdateDpi();
this.RenderContext.DpiScale = scale;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this really planned? Slightly inconsistent with the rest of the PR and its description.
P.S. I periodically push new changes to my fork - https://github.com/HavenDV/H.OxyPlot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this.

For Skia/WPF it's fine I believe as it's handled at a different level, but does look like a regression for non-Skia/WPF which is a bit hard to spot, but the most obvious thing is that axis lines are fuzzy when the scale isn't 1.

@albtaeler do you recall if there was a particular reason for removing this, or did it just look redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember a specific reason. Maybe it was a merge accident, or for redundantency reasons. But I think you're right, it's still needed for the non-Skia/WPF renderer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albtaeler thanks for taking another look; feel free to open a PR putting this back in; hopefully I'll get around to it eventually otherwise.

/// </summary>
protected void Render()
{
if (this.plotPresenter == null || this.renderContext == null || !(this.isInVisualTree = this.IsInVisualTree()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises questions too - it cannot throw a NullReferenceException. If it's just a refactoring - then the behavior is changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mentioned in #1798 (comment) but looking briefly now it does look a bit odd.

I'll try to find time to take another look at this (I should have some tests lying around somewhere....); my WPF knowledge is pretty limited, so I'd welcome any input from you and @albtaeler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't see the comment. Considering it, it's all right. The only question is - did this check play any role in performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the only reason for this check was that this.TransformToAncestor() fails with a NullReferenceException without my changes. As mentioned in #1798 (comment) I changed this behavior, because rendering it's not possible if it isn't in the VisualTree, but sometimes needed.
I could not see any performance changes. It is important that the property this.isInVisualTree = this.IsInVisualTree(); is set.

Copy link
Contributor

@HavenDV HavenDV Feb 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused at this point only because I don't see a place where IsInVisualTree() could throw a NullReferenceException.

@albtaeler albtaeler deleted the Issue1798 branch February 11, 2022 09:41
@VisualMelon VisualMelon mentioned this pull request Feb 12, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OxyPlot SkiaSharp renderer throws a null reference exception if the rendered UIElement has no PresentationSource

3 participants