Acknowledged

String.toCharArray() crashes if the string contains Swedish characters

A user reported a crash in my data field, and I eventually narrowed it down to a line of code that was calling toCharArray() on a user-provided string.  In this case, the string was "Östra Hällsjön".

A single umlauted character is enough to cause toCharArray() to crash.  For example:

var testStr = "Ö";
var chars   = testStr.toCharArray();

In the simulator, the debug console shows:

Error: System Error
Details: Failed invoking <symbol>
Stack: 
  - compute() at C:\dev
{filename}.mc:178 0x10000d9c 

The line number is the line with the call to toCharArray().  I have not done extensive testing to see what other characters may cause it to crash.

SDK:  6.2.2

Devices:  Epix2 51mm, Fenix 6X, Edge 1000

  • Okay.  As far as the simulator goes, if I hardcode the (Swedish) string, it works fine.  My data field is displaying the value of Activity.Info.nameOfNextPoint, which I set via the Simulation -> Set Navigation Data menu option.  When I display the same string, but grabbed from "nameOfNextPoint", the Swedish characters are not displayed properly - they show a diamond with a "?" inside.  The string displays fine on an actual device, though.  (When it is getting that value from a course that the user loads.)

    I also created a SimpleDataField to check the call to toCharArray() against a hardcoded string, and it did not crash.  It still crashes in my data field, so I have no idea why the crash is ocurring - but that call is definitely the culprit.  Removing the swedish characters from the string eliminates the crash.  I will continue to try to create a simplified project that can recreate the problem.

  • Interesting.  I'm traveling right now, but I'll create a stripped-down data field when I get back on Monday/Tuesday.  If I'm still able to recreate it, I'll share the whole project.

  • - I'm not able to reproduce this. Here is my test app code...

    class NoBuenoView extends WatchUi.View {
    
        hidden var _mLines as Array<String>;
    
        function initialize() {
            View.initialize();
    
            _mLines = [] as Array<String>;
        }
    
        function onShow() as Void {
            _mLines = [] as Array<String>;
            _mLines.add("Östra Hällsjön");
            _mLines.add(_mLines[0].toCharArray().toString());
        }
    
        function onUpdate(dc as Dc) as Void {
            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_WHITE);
            dc.clear();
    
            var cx = dc.getWidth() / 2;
            var cy = dc.getHeight() / 2;
    
            var font = Graphics.FONT_TINY;
            var fy = dc.getFontHeight(font);
    
            cy -= (fy * _mLines.size() / 2);
    
            for (var i = 0; i < _mLines.size(); ++i) {
                dc.drawText(cx, cy, font, _mLines[i], Graphics.TEXT_JUSTIFY_CENTER);
                cy += fy;
            }
        }
    }

    Here is the result displayed on the three simulated devices on the 6.2.2 simulator. I don't read or write Swedish, but the characters look right to me. At least they look just like what appears in source displayed in vscode.

    I also tested this on physical hardware, including epix2pro51mm, fr935 (a close approximation to fenix6xpro), and edge1030 (as close as I can get to a physical edge_1000). The app didn't crash on any of the devices, and produced output consistent with what I'm seeing in the simulator.

    I also tried building with several different SDK versions back to 4.1.3 and had no issues.

  • I'll add that the 6.2.2 simulator does not display the Swedish characters properly.  But they seem to display okay on the actual device.

    Also, other String functions (like substring) seem to work fine.  toCharArray() is the only one I have found so far that crashes.