Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

why to check for "IsDisposed" property of SharpDX object?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    why to check for "IsDisposed" property of SharpDX object?

    two questions:

    1) In docs ( https://ninjatrader.com/support/help...arpDXResources ), it is said:


    Click image for larger version  Name:	Cuvddcq.png Views:	0 Size:	33.2 KB ID:	1104706

    However, in none of code i have ever seen such approach (to use .IsDisposed property) to check if object is disposed or not.
    In the above example, i assume the documentation just skipped the theoretical code parts which might have been between the two lines (where creating the object and making check of ".IsDisposed"). is my understanding correct?

    or there might happen theoretically a case, that within same "OnRender" cycle, if we just don't dispose the object ourselves, it might be disposed by the program? So, why we need to check for "IsDisposed" if we see we dont have a flaw in the coding of disposable object?
    probably you understand the question, so once again, does it ever happen that object might be disposed "itself" that makes us forced to check for "isDisposed"?


    2) a bit after that in documentation, there is mentioned the phrase:
    "Instead, you should construct a SharpDX Brush directly if a WPF brush is not ever needed"
    my question is, is there the word "not" a mistake? because it makes a suggestion to us, and i think it should have said "..brush is ever needed" and "not" is mistake there. Is my udnerstanding correct?

    3) in the bottom of that page, it is said that "RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive" uses higher quality rendering (but has performance impact). Are there any few visual examples, of how much does that setting makes rendering better?
    so, some examples of pictures we could look at (drawings, lines, etc...) with and without it and can see "how much better does that property makes drawings" ?
    Last edited by ttodua; 06-13-2020, 03:50 AM.

    #2
    Hello ttodua,

    Thanks for your question.

    The Help Guide is advising to check if the brush or other SharpDX resource is disposed before we use it. You can think of this like accessing an object after we make a null check. The code where you do not see this is not used likely assumes that the code is written to always handle disposing and recreating the resource when appropriate. Code that we have written where SharpDX resources are disposed and recreated properly does not check if the brush/resource is disposed before accessing in OnRender, because our code assumes it should be.

    With #2, the Help Guide is stating if we do not need a WPF Brush, we shouldn't use one. For example, if we have some code that sets custom colors for something drawn on the chart for each bar, we should store the information for each brush's RGB values in Series objects, so the RGB values are tied to each bar, and then custom rendering can create ShrapDX brushes based off of those RGB values. If we store a WPF Brush for each bar, we will likely hit the WPF brush limit.

    AntiAliasing applies a better visual result with less "jaggies" or hard pixelated edges. Anti Aliasing will enlarge a picture, blur it, and then shrink it down to original size to blend colors and hide the hard pixel edges. This has a cost, but since it is offloaded to the GPU with SharpDX, I do not think you would see much impact using it.

    We look forward to assisting.

    Comment


      #3
      thanks, excellent answer!

      Comment


        #4
        sorry, i've revised my #2 question and i think i have a slight confusion still. your advise is quite good (so, not to use `Series<System.Windows.Media.Brush> `, right?) but what you say is not noted in docs (would be good to be added there too).
        just in docs, it says not to use: `.ToDxBrush(RenderTarget)` and instead use `new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Blue);`

        so, my question is, as a replacement of WPF brush series, can we just use SharpDX color series?

        so, i.e.
        ```
        Series<SharpDX.Color> myColors..

        OnbarUpdate(){

        myColors[0]= SharpDX.Color.Blue;
        }
        ```

        and use that in OnRender. Do you think it will have better performance?

        Comment


          #5
          Hello ttodua,

          We would be focusing on the WPF brush limit and how expensive it is to convert the WPF brush to a SharpDX brush.

          If we made custom WPF brushes for each bar, we would very easily hit the brush limit. Reusing WPF brushes is usually fine as long as we aren't creating many new brushes. Creating a Series<System.Windows.Media.Brush> would be problematic if the brushes stored are custom WPF brushes.

          Storing SharpDX colors in a Series would not be device dependent so this would be a good approach to store color information per bar, and avoid converting from a WPF brush in OnRender or OnRenderTargetChanged. (Which can be expensive if we need to convert many brushes in a render pass, for example.)

          Let us know if you have any additional questions.

          Comment


            #6
            Thanks Jim ! excellent.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X