Android Question Weird behaviour in debug mode....why?

Johan Schoeman

Expert
Licensed User
Longtime User
This is the weirdest thing that @Mahares has brought to my attention. At about line 96 of the attached project the following line of code appears:

B4X:
mlc1.XaxisLabelPosition = "BOTTOM"

If you run the project in release mode then it draws the x-axis labels at the bottom or top i.e in the right place depending on BOTTOM or TOP being set. But in Debug mode it draws the x-axis labels only at the TOP regardless of setting it to BOTTOM. What in this lifetime is happening here...? Why does it do so...?

The library files for this project are in the /Files folder of the attached B4A project. Copy them to your additional library folder to test this weirdness...

Can anyone give an explanation for this...?
 

Attachments

  • b4aMPMultiLineChartV4.zip
    377.6 KB · Views: 312

Mahares

Expert
Licensed User
Longtime User
I observed the same thing as @Johan Schoeman. With B4A 5.5, when I run the project in Rapid Debug, if this line:
mlc1.XaxisLabelPosition = "BOTTOM" is in the code the labels show up on top of the graph, But if I run the project in Legacy Debug or Release mode the project works as expected. The labels show up at the bottom of the graph.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Try to add some log messages with BA.Log in renderAxisLabels. My guess is that onDraw is called before the property is set.

With the log messages you can see when it happens and what are the values of mXAxis.getPosition(): BA.Log("position: " + mXAxis.getPosition())
Will do so Erel and will let you know. But why does it only happen in Rapid Debug mode and not in Release mode?
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Hard to say without further debugging it.
Erel, it seems to me I got caught by one of the "newbie" pitfalls in Java. Compared two strings with == and not with string1.equals(string2). Changed the code and now it is working fine in Release, Legacy Debug and Rapid Debug. Nevertheless quite interesting that in Release and Legacy Debug it did manage to draw the labels in the correct place despite comparing the strings with ==. I don't quite understand this. Or do you think it might be something else in the code that causes the problem and by changing the string comparison I have just applied a plaster to stop the bleeding?

The sequence of events seems to be fine when I added debug statements i.e XAxis.java gets initialized, then the call from B4A, and then the call to XAxisRenderer.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The string comparison is the cause of this issue.

In release mode the Java compiler adds all the literal strings to the internal strings pool. So two equal strings (from the code) will point to the same object.

In rapid debug mode the string comes from a different process so it points to a different object.
 
Upvote 0

mr23

Active Member
Licensed User
Longtime User
This also seems to apply to strings used for Char variable tests, with at least IDE 5.5?
B4X:
Dim c as Char
If c = """" Then ...
"""" should end up as a just one <doublequote>.
This comparison works in 5.5 in debug, but in release it fails, while c = CHR(34) does work in release.

I didn't go back and retest it, but I believe the c = """" in release worked in 5.0.2 and prior, or at least prior to 5.0. Not 100% sure of my test case coverage when using 5.0.x.


Update: question moved to https://www.b4x.com/android/forum/threads/char-comparison-failed-in-release-mode.62505/
 
Last edited:
Upvote 0
Top