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.?
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.
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)
@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
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?
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.
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?
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.
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.
The video you posted is running a different code. Post a video of the project you've uploaded. Run it in release mode. Never run anything in legacy debug mode.
Post it in such way that we can see the full logs and code.
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.
@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.
Many apps run on many Android 8.1 devices and never such an error was reported. I guess that something is broken on the device ROM or CPU. It manifests when it is on high load.
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.