codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.67k stars 401 forks source link

EXC_BAD_ACCESS on String.format() on iOS #2805

Open kutoman opened 5 years ago

kutoman commented 5 years ago

error:

Bildschirmfoto 2019-05-17 um 15 55 45

originated from:

    private fun secsToText(secs: Int): String {

        val m = secs / 60
        val s = secs.mod(60)

        return ("%d:%02d").format(m, s) //<--- 
    }

xcode stacktrace:

#2  0x00000001092569ca in java_lang_String_format___java_lang_String_java_lang_Object_1ARRAY_R_java_lang_String at /Users/SoftwareDev/Downloads/sources 17/dist/HacUmraDuaGuide-src/nativeMethods.m:1616
#3  0x00000001097c0af5 in com_igmghacumre_duaguide_view_DuaPlayer_secsToText___int_R_java_lang_String at /Users/SoftwareDev/Downloads/sources 17/dist/HacUmraDuaGuide-src/com_igmghacumre_duaguide_view_DuaPlayer.m:2044
shannah commented 5 years ago

It is strange that this didn't get caught in the compatibility compliance check during compile. String.format() isn't part of the CLDC11 jar, and likely won't work on other platforms as well. I think I implemented it in ParparVM to satisfy some internal Kotlin stuff that relied on it.

Looking at my implementation, it seems that it will only work for formatting Strings right now. It's a bit tricky to get it working correctly for other types of parameters.

kutoman commented 5 years ago

but this code runs on Android without problems.

shannah commented 5 years ago

The CLDC11 jar is the "standard" runtime library that CN1 apps must conform to. The app will ultimately run on the platform's runtime library, which will be a superset of the CLDC11 jar. E.g. On Android it will run directly against the device's runtime. On iOS it will use ParparVM's runtime library. When we compile apps, we check for compliance with CLDC11 to guarantee runtime compatibility with all CN1 target platforms.

If this compliance step is skipped, then the code might run on a given platform, but also might not.

kutoman commented 5 years ago

ok I see. I will use a custom format method instead.