Clear Canvas -> Black Canvas

  1. 2 months ago

    Robert L

    Mar 14 Federal Way, WA (Seattle Area)
    Edited 2 months ago

    macOS Mojave Version: 10.14.2
    Xojo 2018 Release 4
    I have an app that is "older" in the sense that I have been working on and off on it for a couple years. So it has seen various versions of Xojo.
    I have recently been re-jiggering canvases to embrace Group2D and Object2D.

    I have code to clear the canvas. When I run that code I am expecting the canvas just to clear. But instead it becomes solid black.

    Trying to understand this happening, I wrote a simple sample app with a single canvas. In the sample app, I use the same code. When I clear the canvas, it does what I expect: the canvas clears.

    So I disassembled my original app, discarding all the pieces slowly trying to find out what was "different". Finally, the original app was reduced to just a single window with a single canvas. But the behavior persisted. Running code to clear the canvas results in a solid black canvas.

    Here is the code present in both applications. All the action takes place in the paint event of the canvas (cnLook)

    cnLook: paint event

    If Self.bClear Then
    g.ClearRect(0, 0, g.Width, g.Height)
    Self.bClear = False
    End If
    
    If Self.bSquare Then
    // g.DrawObject(Self.someShape, 100, 100)
    
    Dim r As New RectShape
    r.Width = 75
    r.Height = 75
    r.Border = 100
    r.BorderColor = RGB(0, 0, 0) // black
    r.FillColor = RGB(0, 127, 127) // teal
    r.BorderWidth = 2.5
    
    g.DrawObject(r, 100, 100)
    
    Self.bSquare = False
    End If

    The window has two properties (Booleans)
    bSquare
    bClear

    The window has two buttons with the Action code below.

    pbClear: Action

    Self.bClear = True
    Self.cnLook.Invalidate

    pbDrawSquare: Action

    Self.bSquare = True
    Self.cnLook.Invalidate

    Canvas Setting are the default in both:

    Appearance:
    Visible, AutoDeactivate, Enabled, UseFocusRing All ON

    Behavior
    Accept Focus, AcceptTabs, Double Buffer: All these OFF
    Transparent: ON

    The logic of all this is fairly straight forward. The user clicks on one or the other of the buttons. The window property bSquare or bClear get set to True and the invalidation of the canvas forces the Paint event to fire. The line of code below, is intended to clear the canvas but behaves differently in the two apps.

    g.ClearRect(0, 0, g.Width, g.Height)

    When pbClear is clicked in one application the canvas turns black. In the other application it is cleared.
    When pbDrawSquare is clicked, both applications behave identically. A square is drawn on a clear background.

    I am confounded by this. I am asking to see if anyone has seen something like this or knows how to "correct" my old app so this behavior does not occur.

  2. Robert L

    Mar 14 Federal Way, WA (Seattle Area)

    Curious phenomena possibly related to the above. I had thought of posting a screenshot showing the screens of the two apps. One with the solid black canvas and the other with the clear canvas. So I put the two windows adjacent to one another and tried a Mac screenshot. (Shift-Command-4)
    The screenshot does not actually show what I see looking at the screen. I have never encountered this doing hundreds of screenshots over the years.
    The black canvas does not show up as black. Instead it looks clear. Indistinguishable from the screen of the app that appropriately clears the canvas.
    It is some bad Mojo (?bad Xojo)

  3. Beatrix W

    Mar 14 Pre-Release Testers Europe (Germany)

    There have been a couple of reports about this behaviour. See for instance Feedback Case #54430.

    Are you trying to do a screenshot in DarkMode? The windows are now partially transparent and the screenshots don't capture that.

  4. Robert L

    Mar 15 Federal Way, WA (Seattle Area)

    No I am not using Dark Mode currently. But I suspect that Dark Mode may ultimately prove to be the cause of the problem. Here is a photograph of my screen taken with my iPhone.

    https://1drv.ms/u/s!AomRm_Ft4xvQg-xroxg5C29xlO_k_Q

    There are three images of two windows side by side. Those are the two apps. The app on the left shows a black canvas. The pair as seen is the middle is the "Screenshot" of the two windows seen immediately above it. Note the "black" canvas is now clear. This is the png that Screenshots produce. When that is converted to a jpeg, it is seen with the white background "lowest" pair.

    As I noted earlier, I have never before seen a Screenshot that failed to reproduce what is actually seen by the user on the monitor. I had thought that screenshots were simply pictures of the pixels on the screen with no awareness of "transparency " or whatever.

    I have created a new project. I have then copied, one by one, the elements of the app that contains the black canvas to this new project. (I copied the canvas, the generic buttons, and two Boolean properties of this simplified app). The new project behaves properly. No black canvas.

    So somehow, the app that produces the black canvas is "corrupted". Although I am not using Dark Mode currently, I have used it in the past when working on the now corrupted app. I noticed that Xojo had a problem sometimes when I had gone back from Dark Mode to Light Mode in showing (in Light Mode) the Find text box with a black background. Since text in Light Mode is black, you could not see what was being typed in the Find text area of the IDE. For this reason, I had stopped using Dark Mode during any development with Xojo.

    This does not solve my problem of an app that has been corrupted. Trying to isolate the problem, I took the app in question and stripped almost everything from it for demonstration purposes. But it, in fact, is a very large app. I am not sure how easy it is going to be for me to apply my cure of creating a new project and copying the individual elements over, one by one. The actual app has many windows, classes, modules etc. And it is "corrupt".

    In summary, I suspect that my app was corrupted by having part of its development done in Dark Mode. This is not going to be a simple thing for me to deal with. I cannot prove that Dark Mode is responsible for the corruption. It is my best guess for these bizarre symptoms. My advise to others is to AVOID USING DARK MODE when developing with Xojo.

  5. Norman P

    Mar 15 Pre-Release Testers, Xojo Pro Alberta Canada

    I can say that I used Dark mode when working on the IDE itself
    And I'm sure Greg has/is as well

    Theres likely something else different like

    • is Supports HiDpi on or off in both apps ?
    • is transparent set for the canvas in both ?
  6. Beatrix W

    Mar 15 Pre-Release Testers Europe (Germany)

    Do you have transparency set for your canvas? Do you have overlapping controls?

    Don't make your screenshots in jpgs but do them as png. You should then be able to see where the screenshots are transparent.

  7. Robert L

    Mar 15 Federal Way, WA (Seattle Area)

    Thank you Norm.

    Theres likely something else different like

    is Supports HiDpi on or off in both apps ?
    is transparent set for the canvas in both ?

    Transparent is set for the canvas in both.

    Now I had never heard of Support HiDpi before Norm's comment. When I looked it up and went to the setting in the Inspector for Build Settings Shared I saw the the properly functioning app had Supports Hi-DPI set to ON and the old app that was not working had it set to OFF. So I switched it on in the old app. That made no difference.

    But I also noticed, just below it, the switch for Supports Dark Mode. That was ON for the properly functioning app and OFF for the old problematic app. I switched it ON for the old app and the problem goes away. Yea!

    So it appears to me that this old app, created before Dark Mode ever existed, had the setting for Support Dark Mode set for OFF. In my limited experience, it appears that new apps have this switched ON by default.

    It is not my intention in particular for my app to support Dark Mode. But having Supports Dark Mode. set to ON cures a problem that I was seeing. Having it OFF made my canvas flaky.

    I do not know whether this is due to the fact that I spent some development time in Dark Mode as I had speculated above or whether this would have happened anyway. I also do not know if there is any advantage to having Supports Dark Mode. set to OFF. But it seems that if your app is old enough, that is the setting that it will have. In my case, I was seeing problems with my Canvases clearing. And it seems, and I hope that this will be the end of the problem, that setting Supports Dark Mode. to ON makes the problem go away.

  8. Robert L

    Mar 15 Federal Way, WA (Seattle Area)

    Beatrix, thanks for chiming in.

    1. All the canvases have Transparent set to ON. That seems to be the default.
    2. I have been making my screenshots in PNG which I believe is also the Apple default. The screenshot (png) did not "see" the black canvas of the old app. As I say, I was startled by this because I thought that Screenshots were just pictures of what was on the monitor rather than something more complex.
    3. No overlapping controls.
  9. Alfred V

    Mar 15 Pre-Release Testers

    As far as I can judge based on own experience, it very likely is due to an old project used in a recent Xojo version. The remedy I found was to copy one by one the subclasses and paste them one by one in the fresh project. Then current instances (Window1, Canvas1 etc are set to their superclasses that were pasted.

    I think also that Arbed could help.

    I have been there, done that.

    Hope this will help

  10. Greg O

    Mar 15 Xojo Inc

    We are aware of this problem and will fix it in a future release.

or Sign Up to reply!