Bug? Comparison IF THEN does not always work in debug mode

Star-Dust

Expert
Licensed User
Longtime User
In my App, I compare two variables

When I compile in release mode it always works correctly. But sometimes after some times when I compile in DEBUG the IF THEN comparison always gives me false, even if looking at the logs the numerical values are the same.
Recompile in RELEASE and it works correctly, I go back to debugging and the problem returns.

Even if I clean the project I have no better results. If you restart your PC and iPhone then everything gets back in place.

What will be?
B4X:
Dim I as Int = 1

Log(i)
Log(G.INTvalue)
If i=G.INTvalue then
    ' code
End if
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Already done and are two identical integers:(

However in Release Mode it does not happen, only debug mode
 

Sagenut

Expert
Licensed User
Longtime User
Try using ( )
B4X:
If (i = G.INTvalue) then
    ' code
End if
 
D

Deleted member 103

Guest
Recompile in RELEASE and it works correctly, I go back to debugging and the problem returns.
In release mode the compiler runs faster and it may be that the variable, in the case of the IF query, is already initialized.
In debug mode the compiler runs slower and therefore the variable is not yet initialized for the IF query.
Where and when is the variable initialized?
Of course, that's just a guess.
 

Star-Dust

Expert
Licensed User
Longtime User
What is G.INTvalue ?
G is a class that contains only CONSTANTS

IntValue contains a constant of value 1.
The G class is certainly initialized first because G.IntValue appears with the value 1 in the logs
And also I (which is an int variable) in the LOG appears with the value 1

I do the LOG before the IF, so when it comes to the comparison I am sure they are two integers with the same value

I also tried

B4X:
IF I = 1 then
END IF

Where I is certainly 1 because it appears in the LOGs with the value 1 and the comparison fails
 

Star-Dust

Expert
Licensed User
Longtime User
Is g.INTValue an int variable?

Have you tried to reproduce it in a small project?
G is a class that contains only constants.
Yes, I can reproduce it, unfortunately it doesn't always happen.
And if I reboot everything is settled.

Tomorrow I will try to create a small code to reproduce the error
 

emexes

Expert
Licensed User
Tomorrow I will try to create a small code to reproduce the error
+1

Or: show us the definition and declaration of G, and add log lines to the If and Else branches, eg:
B4X:
Dim I as Int = 1

Log(i)
Log(G.INTvalue)
If i=G.INTvalue then
    Log("equal")         'add this line
    ' code
Else                     'add this line
    Log("not equal")     'add this line
End if
 
Last edited:

Markos

Active Member
Licensed User
Longtime User
It seems the problem may not be programmatic but infrastructure with respect to OS , service packs etc. If you are getting intermittent errors with
if i=1 then, It has to be compiler parsing problem, make sure you are compliant with all service packs and java versions and possible b4i version. Erel would be best to say which may be out of date based on what core lib etc you are using in conjunction with b4i.

just my 2 cents worth.
 

Markos

Active Member
Licensed User
Longtime User
Oh also, state if the release version is created using hosted builder or local
 

Star-Dust

Expert
Licensed User
Longtime User
hosted builder
 

thetahsk

Active Member
Licensed User
Longtime User
try
B4X:
If ( G.INTvalue=i) then
    ' code
End if

or

If (i - G.INTvalue=0) then
    ' code
End if
 

emexes

Expert
Licensed User
What is the type of G.INTvalue? How is it initialized to its constant value? Please post at least all the lines of the class that contain the text "INTvalue", even if they are obviously correct ;-)

Better yet: how's that small code example of the problem coming along?
 
Last edited:

Markos

Active Member
Licensed User
Longtime User
Guys check his previous post where he states...
"
I also tried

Code:
IF I = 1 then
END IF"

So the problem is not in G.INTvalue it is something in his compiler or libraries that is not configured properly or not updated properly.

If he can probably reinstall from scratch if not surgically identify what was changed in B4i or library or service pack or .Net framework. Try to spoon feed the compiler with different logic is sadly in my opinion not the solution just symptomatic to a buggy compiler state.
 

Star-Dust

Expert
Licensed User
Longtime User
The problem does not always occur but after a few compilations and returns to normal restarting iphone
 

Markos

Active Member
Licensed User
Longtime User
Ok the behaviour now suggests an iphone interaction with IDE or iOS OS or Menory isuue. Do u have another iphone to test the App in debug mode. This will at least remove iphone as being part of the cause
 

emexes

Expert
Licensed User
So the problem is not in G.INTvalue
You'd think so, based on that, but... in the heat of programming battle, and especially when people are under pressure of deadline, you have to remember that programmers are human too. If I take verbatim:
B4X:
IF I = 1 then
END IF"
then I can tell immediately that this was not copied from the source code, but typed in manually without going through the IDE. Don't know what the heck the quotation mark is, either. So... is that the code that was run? And how do we know the "comparison fails"? Is this based on the debug trace cursor?
it is something in his compiler or libraries that is not configured properly or not updated properly.
Could it be the compiler? Perhaps, although: the Ifs don't appear to contain references libraries or service packs or other external code not generated by the compiler, and if there was some problem in runtime JIT handling of If statements and integer operations, then this would manifest itself much more widely.

But your idea could be right. Quickest way to rule out the build environment being the problem might be: recompile a previous (known, working) program, see if it still works. Presumably it will contain many Ifs and integer operations. If older programs still compile and run ok, then that suggests that the build and test environment and hardware are ok, and we are back to: what is it about this particular integer If comparison?

I'm thinking that it could well be either: there is a type or cast or conversion problem, or something is being changed unexpectedly (nested For loops using the same variable are a good trap). But without seeing the actual code that is producing the problem, it's like swatting mozzies in the dark.
Try to spoon feed the compiler with different logic is sadly in my opinion not the solution
Not sure what this is in reference to. What I see in people's suggestions here are two primary keys to debugging: divide and conquer, and trust but verify.
 
Top