Acknowledged

bug: System.println and static inlined strings in the simulator cause the wrong string to be used

The following code ran on any device with at least CIQ 3.4.0 that supports toasts (i.e: fr955) in the simulator (either 7.4.3 or 8.0.0-Beta) will incorrectly display "other" instead of the expected "toast".

System.println("toast");
if (WatchUi has :showToast) {
    WatchUi.showToast("toast", null);
}
System.println("other");

I'm not 100% sure whether the bug is in println or maybe showToast or how the simulator implements some string functions or if it's a bug in the compiler, but the above few lines clearly reproduce it. I created a new Watch App with the Monkey C extension, and put the above code somewhere.

Note that the text logged is correct, only in the toast it's incorrect.

Parents
  • My theory is something like this happens (based on my example, but of course if we collect more examples then it can be fine tuned):

    - compiler sees "toast" string literal in multiple places and puts 1 string constant to the data and uses a reference to it in all places.

    - somewhere the simulator has a bug that causes it to change the string in some static pointer because it assumes that the execution is done on 1 thread, ... so in my example some pointer points to the "toast" string and then the 2nd println updates this pointer (or rather copies "other" to some buffer that is used by it?) 

    - the toast is not displayed at the time showToast is called but some time later probably after onUpdate

    - but the bug causes the buffer to where the string passed and for the meantime kept in showToast to be changed to "other"

    Again I don't really know what happens or how, and have 0 insight to the simulator's code so it's just guessing.

Comment
  • My theory is something like this happens (based on my example, but of course if we collect more examples then it can be fine tuned):

    - compiler sees "toast" string literal in multiple places and puts 1 string constant to the data and uses a reference to it in all places.

    - somewhere the simulator has a bug that causes it to change the string in some static pointer because it assumes that the execution is done on 1 thread, ... so in my example some pointer points to the "toast" string and then the 2nd println updates this pointer (or rather copies "other" to some buffer that is used by it?) 

    - the toast is not displayed at the time showToast is called but some time later probably after onUpdate

    - but the bug causes the buffer to where the string passed and for the meantime kept in showToast to be changed to "other"

    Again I don't really know what happens or how, and have 0 insight to the simulator's code so it's just guessing.

Children
No Data