Android Question strange behavior in release mode

markcasio

Member
Licensed User
Longtime User
Hi, I have a question , what can cause a local variable in a sub to change it's value randomly.
The local var is not double used as a global var, and is only used in sub part1.

B4X:
sub part1
Dim k1,k2,k3,k6,k7,k8,k9,k10,k11,k12,k13 As Int '<=== local vars
k12 = 1234
 Log("k12 ="&k12) '<===== always gives 1234
anothersub '<== calling another sub
 Log("k12 ="&k12) '<===== always 1234 in debug but in release mode i somethimes get 357302632
end sub

What can cause a local variable to change it's value only in release mode.?
 

markcasio

Member
Licensed User
Longtime User
I could narrow the project to a few useless subs and cause the problem.
Here is a simple project, the longer it takes for another sub to return to the problem sub the faster the problem occurs, that is why i could simulate it on the first iteration with allot of work delay in another sub.
In the complete application it happens from time to time, what makes it difficult to detect.
I hope someone can simulate the problem, because as i told you it works on several other android devices in release mode but not on android 8.1.0. as proven in the video.
 

Attachments

  • 1.zip
    8.8 KB · Views: 254
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
Afraid I can only confirm it runs (in release mode) without error on my Galaxy S20, Android 10. It ran the original 100 loops on, so I increased it to 1000. That has run without fault too.
I can only suggest you revert to using the correct Java Dev Kit (OpenJDK 11) rather than the V14 you have.
Don't know if relevant but the SDK level for Android 8.1.0 is 27 (?targetSdkVersion)
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
@MikeSW17 Thank you for your test, i will try openJDK 11 just in case.
Changing the value of the double for next loop in anothersub , controls the fail frequenty for me in android 8.1.0
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
I have installed openJDK11 same result.,
Also tested the application on virtual device 8.1.0 in windows, works fine.
 
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
[*Written while you were posting #25 just above]

To add to my previous, I have also just tried running your project under an Android 8.1 (Oreo) Emulator from SDK version 27'
It runs without fault (500 cycles). The issue would seem to be specific to your your configuration in some manner.
My money would be on misusing JDK 14 instead of OpenJDK 11 as specified for B4A.

That said, the only change I made to your project was to add " #BridgeLogger: True" to the Project Attributes to get the log messages.
Is that how you get the Log messages in Release Mode?
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
I'm directly connected to the hardware using a usb otg cable , i can see the logs in release mode from the device.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Unfortunately a lot happens between the Java code and the device CPU executing real instructions. Firstly the compiled Java bytecodes are translated from the stack architecture of the Java Virtual Machine to the bytecodes of the register oriented Dalvik Virtual Machine and then the Android Runtime further translates the Dalvik codes to native code on installation so the conceptual view of the Java code executing in a stack based environment cannot be mapped to the actual execution environment. For example if this were occurring in a non-managed environment I would suspect stackcorruption, where local variables are located, from a misused pointer to a local variable - but that abstraction is not valid at runtime in an Android device.

As Erel says the version of Java should make no difference.
 
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
Am I right that this problem is only happening with one single device (that you know of)?
If so, is it possible to back it up, factory reset and test again on a clean set-up?
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
changing to openJDK11 had no effect.
When i change myvar to a string it keeps its value, no problem
Converting the string to int after the sub , no problem.
When i change myvar into an integer array no problem.
When i convert more string variables into intgerer myvar1 myvar2 myvar3 myvar4 only myvar1 myvar3 are changing value, myvar2 and myvar 4 are ok.
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
I have more than one device from the same brand all android 8.1.0 all new devices , factory reset, there are no other 3de party applications installed.
 
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
I have more than one device from the same brand all android 8.1.0 all new devices , factory reset, there are no other 3de party applications installed.
Do you have access to any other 'similar' (but not same brand) Android 8.1.0 devices (besides emulators)?
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
@Erel
you are right , the first video was made before i could narrow down the problem to a small project.
I've uploaded a new video with the source code used and log file.

var problem video2
 

Attachments

  • 1.zip
    8.7 KB · Views: 221
  • problem_log.txt
    80.5 KB · Views: 229
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you tried searching google to see if there is wider reporting of problems on the specific device with android programmers generally?
 
Upvote 0

markcasio

Member
Licensed User
Longtime User
Yes high load will trigger the problem, if you make 'another sub' resumable by adding sleep(0) the problem disappears.
But i have to prove that the application is not causing the problem, no one would believe that my local variables are changing value.
I have contacted the hardware company , i will keep you informed.
 
Upvote 0
Top