Bug? Not sure if its a bug, but...

Cableguy

Expert
Licensed User
Longtime User
I am getting errors in runtime after compilation in a strange situation...

I have a few views created by code, and positioned relative to other views.
I then try to manipulate some props using canvas.
With screen on, the app works fine, BUT, with screen OFF, it compiles and errors with the canvas complaining about the width and height of the targeted view having to be greater than zero.
To trouble shoot I placed a simple log statement

B4X:
Log(Props1Header.Width)

and to my surprise, screen ON gives positive values, but screen OFF gives NEGATIVE values... Height returns always positive values.

I am connecting my device by usb cable
 

Cableguy

Expert
Licensed User
Longtime User
I will only be able to in late afternoon, but all i did was create 6 panels in code, initialised them and set their color drawable to get the round corners and borders. I then added 6 labels one for each panel, and did the same with their color drawable. The panels are placed with the same height/width and spaced vertically relative to the previous one. The labels are place inside the panels, one per panel, and have fixed height and take the panels width.
I then call a sub passing the label as view.
In this sub I initialise a canvas and set its target to be the passed view. In this sub I only have that, plus two log statements to show the passed views height and width.
With my phone connected by USB ( haven't tested using bridge), if the screen is ON when deploying, the width value is positive, but if the screen happens to be or to go OFF, the the value is returned as a Negative (ie: 800 vs -800).In which case the app crashes at the canvas, conplaini the view width/height must be larger than zero.
Placing the same log in the main sub, after all views are set and placed, gives the same values (positive/negative)
 

Cableguy

Expert
Licensed User
Longtime User
The expected behavior is that the activity is paused when the screen turns off so no canvas related code should be executed at that point.
I understand that, but why is the view width negative???

my main is as follows

B4X:
Sub Activity_Create(FirstTime As Boolean)
  
Panel1.Initialize("Props1")
Header1.Initialize("")
Private ACD As ColorDrawable
ACD.Initialize(Colors.LightGray, 5dip)
Activity.Background = ACD
  
    Private PCD As ColorDrawable
    PCD.Initialize2(Colors.Gray, 3dip, 2dip, Colors.DarkGray)
    Panel1.Background = PCD
  
    Private PHCD As ColorDrawable
    PHCD.Initialize2(Colors.Cyan, 3dip, 2dip, Colors.DarkGray)
    Header1.Background = PHCD
  
    Activity.AddView(Panel1, 1%y, 1%y, 50%x , 10%y)
  
    PropsPanel1.AddView(Props1Header, 0, 0, Panel1.Width,10%y)
  
    Log(Props1Header.Width)
End Sub

EDIT : I also found that the values are different, screen OFF = -807, screen ON = 889...
even more puzzled
 

Cableguy

Expert
Licensed User
Longtime User
Although I cannot reproduce it in a blank project, it still happens on my current project and I can't understand why.
So here is my current project, please enlight me why this is happening...
 

Attachments

  • BUG.zip
    12.2 KB · Views: 190

Cableguy

Expert
Licensed User
Longtime User
That way since my app is to be used in landscape, the separator will be placed in such a way that the right side of the activity will be a square, which will then have a square panel
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
The only annoying thing about this is that when it happens, if I'm in hot swap mode making changes in the code, the debugger closes, and the cursor jumps to the "error" line, and sometimes I end up adding partial keywords out of place...
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
The only annoying thing about this is that when it happens, if I'm in hot swap mode making changes in the code, the debugger closes, and the cursor jumps to the "error" line, and sometimes I end up adding partial keywords out of place...
Sounds like your almost atttempting to multi-task and we all know that men should not multi-task, our brains are wired differently to women who are expected to multi-task :p
I hope that I haven't just caught the wrath of @lemonisdead with that comment ;)
 
Top