Search code examples
javascriptandroidwebviewtitanium

web view causing app to crash


Hi I have a very basic app in Titanium. There are 3 web views. When there is wifi from the start all three web views will load fine. I have a check in my code where the webview is only added if there is an internet connection. If there isn't, I add a label explaining to connect to the internet and a refresh button. When i click the refresh button, the adding of the web view crashES the app. Code works in iOS, not android. Using SDK 3.2.3. Code below:

refresh.addEventListener("click", function (e){
        if(Ti.Network.online){
            console.log(" here 1 -----------");
            Navbar.remove(refresh);
            console.log(" here 2 -----------");
            self.remove(NoInternet_view);
            console.log(" here 3 -----------");
            self.add(shopWebView);
            console.log(" here 4 -----------");
        }   
        else{
            alert("An internet connection is required");
        }
    });

The log gets to the printout "here 3 ----------" and then crashes.

Associated log:

F/libc    (12588): Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 12612 (KrollRuntimeThr)
[INFO][DEBUG   ( 1764)] *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
[INFO][DEBUG   ( 1764)] Build fingerprint: 'samsung/lt01wifixx/lt01wifi:4.2.2/JDQ39/T310XXUAMF1:user/release-keys'
[INFO][DEBUG   ( 1764)] Revision: '6'
[INFO][DEBUG   ( 1764)] pid: 12588, tid: 12612, name: KrollRuntimeThr  >>> com.girt.cuddles <<<
[INFO][DEBUG   ( 1764)] signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0000000c
[INFO][DEBUG   ( 1764)]     r0 00000000  r1 5e93c4e8  r2 000000aa  r3 00000001
[INFO][DEBUG   ( 1764)]     r4 00000000  r5 5a386ec8  r6 5e49f9bc  r7 00000000
[INFO][DEBUG   ( 1764)]     r8 5e49f88f  r9 5e49f870  sl 5e49f9bc  fp 5eb506a5
[INFO][DEBUG   ( 1764)]     ip 5ea062f8  sp 5e49f818  lr 5e518473  pc 5e518284  cpsr 40000030
[INFO][DEBUG   ( 1764)]     d0  0000000000000000  d1  4018000000000000
[INFO][DEBUG   ( 1764)]     d2  0000000000000000  d3  000f4240003d0900
[INFO][DEBUG   ( 1764)]     d4  0000000000000001  d5  3ff0000000000000
[INFO][DEBUG   ( 1764)]     d6  0000860100000000  d7  0000860100000000
[INFO][DEBUG   ( 1764)]     d8  0000000000000000  d9  0000000000000000
[INFO][DEBUG   ( 1764)]     d10 0000000000000000  d11 0000000000000000
[INFO][DEBUG   ( 1764)]     d12 0000000000000000  d13 0000000000000000
[INFO][DEBUG   ( 1764)]     d14 0000000000000000  d15 0000000000000000
[INFO][DEBUG   ( 1764)]     d16 0000000000000001  d17 0000000000000000
[INFO][DEBUG   ( 1764)]     d18 0000000000004001  d19 0000000000000000
[INFO][DEBUG   ( 1764)]     d20 3fc554e7eb0eb47c  d21 3e66376972bea4d0
[INFO][DEBUG   ( 1764)]     d22 3f4de16b9c24a98f  d23 3fb0f4a31edab38b
[INFO][DEBUG   ( 1764)]     d24 3fede16b9c24a98f  d25 3fe55559ee5e69f9
[INFO][DEBUG   ( 1764)]     d26 0000000000000000  d27 0000000000000000
[INFO][DEBUG   ( 1764)]     d28 0000000000000000  d29 0000000000000000
[INFO][DEBUG   ( 1764)]     d30 0000000000000000  d31 0000000000000000
[INFO][DEBUG   ( 1764)]     scr 60000013
[INFO][DEBUG   ( 1764)] 
[INFO][DEBUG   ( 1764)] backtrace:
[INFO][DEBUG   ( 1764)]     #00  pc 00078284  /data/app-lib/com.girt.cuddles-1/libkroll-v8.so (titanium::EventEmitter::~EventEmitter()+71)
[INFO][DEBUG   ( 1764)]     #01  pc 0007846f  /data/app-lib/com.girt.cuddles-1/libkroll-v8.so (titanium::JavaObject::getJavaObject()+58)
[INFO][DEBUG   ( 1764)]     #02  pc 0007e157  /data/app-lib/com.girt.cuddles-1/libkroll-v8.so (titanium::TypeConverter::jsValueToJavaObject(_JNIEnv*, v8::Local<v8::Value>, bool*)+302)
[INFO][DEBUG   ( 1764)]     #03  pc 0009a2f9  /data/app-lib/com.girt.cuddles-1/libkroll-v8.so (titanium::TiViewProxy::add(v8::Arguments const&)+332)
[INFO][DEBUG   ( 1764)]     #04  pc 00171034  /data/app-lib/com.girt.cuddles-1/libkroll-v8.so
[INFO][DEBUG   ( 1764)]     #05  pc 00067c00  <unknown>
[INFO][DEBUG   ( 1764)] 
[INFO][DEBUG   ( 1764)] stack:
[INFO][DEBUG   ( 1764)]          5e49f7d8  40043d5c  
[INFO][DEBUG   ( 1764)]          5e49f7f4  4094f6e4  /system/lib/libdvm.so
[INFO][DEBUG   ( 1764)]          5e49f7f8  00000000  
[INFO][DEBUG   ( 1764)]          5e49f7fc  59f04dc8  
[INFO][DEBUG   ( 1764)]          5e49f800  409d1c98  /system/lib/libdvm.so
[INFO][DEBUG   ( 1764)]          5e49f804  57225378  /dev/ashmem/dalvik-LinearAlloc (deleted)
[INFO][DEBUG   ( 1764)]     #00  5e49f818  5ea06218  /data/app-lib/com.girt.cuddles-1/libkroll-v8.so
[INFO][DEBUG   ( 1764)]          ........  ........
[INFO][BootReceiver( 2125)] Copying /data/tombstones/tombstone_05 to DropBox (SYSTEM_TOMBSTONE)
[INFO][dumpstate(13169)] begin
[WARN][ContextImpl( 2125)] Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1346 com.android.server.analytics.data.collection.application.CrashAnrDetector.broadcastEvent:291 com.android.server.analytics.data.collection.application.CrashAnrDetector.processDropBoxEntry:254 com.android.server.analytics.data.collection.application.CrashAnrDetector.access$100:60 com.android.server.analytics.data.collection.application.CrashAnrDetector$1.onReceive:102 
[INFO][Monitor ( 2125)] SIOP:: Current AP = 360, CP = 0
[INFO][dumpstate(13169)] done
[INFO][SurfaceFlinger( 1771)] id=71 Removed UiActivity (2/4)
[INFO][ActivityManager( 2125)] Process com.girt.cuddles (pid 12588) (adj 0) has died.
[WARN][InputDispatcher( 2125)] channel ~ Consumer closed input channel or an error occurred.  events=0x9
[ERROR][InputDispatcher( 2125)] channel ~ Channel is unrecoverably broken and will be disposed!

EDIT: Code associated with map page:

var removeRefresh = function removeRefresh() {
    if(Ti.Network.getOnline()) {
        console.log("issue 1-------");
        self.remove(NoInternet_view);
        console.log("issue 2-------");
        self.add(map1);
        console.log("issue 3-------");
        Navbar.remove(refresh);
        console.log("issue 4-------");
    }
    else alert("An internet connection is required");
};
refresh.addEventListener("click", removeRefresh);

Solution

  • You are destroying refresh (Ti.UI.Button) in an anonymous handler.

    You might try this code:

    var removeRefresh = function removeRefresh() {
        if(Ti.Network.getOnline()) {
           Ti.API.info(" Checkpoint 1 -----------");
           self.remove(NoInternet_view);
           Ti.API.info(" Checkpoint 2 -----------");
           self.add(shopWebView);
           Ti.API.info(" Checkpoint 3 -----------");
           Navbar.remove(refresh);
           Ti.API.info(" Checkpoint 4 -----------");
        }
        else alert("An internet connection is required");
    };
    refresh.addEventListener("click", removeRefresh);
    

    You must are secured of exist NoInternet_view and shopWebView.

    Titanium Studio Console will show the four messages (Ti.API.info)