0

Android app occasionally crashes

asked 2014-08-03 14:42:15 -0700

riko642 gravatar image

updated 2014-08-03 15:02:07 -0700

Hello, I am working on an Android App in Unity. The user can choose to start either a server (enter name->start server) or a client (discover servers->choose one and connect to it). The user can also cancel any of these "states" and return to the previous screen (For example start a server, then cancel it, and start a client)

The app works well, however it occasionally crashes, I don't really know what causes this crash, neither how to debug it. It always crashes after several (10-30) runs and cancels of the server or/and client. It usually crashes during the start of client/server.

The code I am using is here, any idea what can be wrong? (it seems to me like it doesn't correctly stop the client/server)

I have added all my code just in case, but I expect the problem to be somewhere in my StopClient or StopServer functions:

public static bool StopClient() {
    if (sMsgBus == null) return true;
    DisconnectFromFoundName();
    sMsgBus.CancelFindAdvertisedName(SERVICE_NAME);
    sMsgBus.Disconnect(connectedVal);
    if (sessionListener != null) {
        status = sMsgBus.SetSessionListener(null, sSessionId);
        sessionListener = null;
    }
    sSessionId = 0;
    sJoinComplete = false;
    sJoinCalled = false;
    availableServerNames.Clear();
    connectedVal = null;
    sMsgBus = null;
    sBusListener = null;
    testIntf = null;
    opts = null;
    AllJoyn.StopAllJoynProcessing();
    return true;
}

public static bool StopServer() {
    if (sMsgBus == null) return true;
    sMsgBus.CancelAdvertisedName(SERVICE_NAME + "." + serverName, opts.Transports);
    sMsgBus.UnregisterBusListener(sBusListener);
    sMsgBus.ReleaseName(SERVICE_NAME + "." + serverName);
    sMsgBus.UnbindSessionPort(SERVICE_PORT);
    sMsgBus.Disconnect(connectedVal);
    connectedVal = null;
    sMsgBus = null;
    sBusListener = null;
    sessionPortListener = null;
    testObj = null;
    testIntf = null;
    opts = null;
    sSessionId = 0;
    AllJoyn.StopAllJoynProcessing();
    return true;
}

public static bool StartClient() {
    sMsgBus = new AllJoyn.BusAttachment("myApp", true);
    sMsgBus.CreateInterface(INTERFACE_NAME, AllJoyn.InterfaceDescription.SecurityPolicy.Off, out testIntf);
    testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "cat", "ss", "s", "inStr1,inStr2,outStr");
    testIntf.AddSignal("serverUpdate", "s", "json", 0);
    testIntf.Activate();
    if (testObj == null) testObj = new TestBusObject(sMsgBus, SERVICE_PATH);
    sMsgBus.Start();
    for (int i = 0; i < connectArgs.Length; ++i) {
        sMsgBus.Connect(connectArgs[i]);
        connectedVal = connectArgs[i];
    }
    sBusListener = new MyBusListener();
    sMsgBus.RegisterBusListener(sBusListener);
    AllJoyn.InterfaceDescription.Member serverUpdateMember = testIntf.GetMember("serverUpdate");
    sMsgBus.RegisterSignalHandler(SignalHandler, serverUpdateMember, null);
    sMsgBus.AddMatch("type='signal',member='serverUpdate'");
    sMsgBus.FindAdvertisedName(SERVICE_NAME);
    return true;
}

public static bool DisconnectFromFoundName() {
    if (sSessionId != 0) {
        sMsgBus.SetSessionListener(null, sSessionId);
        sessionListener = null;
        sMsgBus.LeaveSession(sSessionId);
        sSessionId = 0;
    }
    sJoinComplete = false;
    AllJoyn.InterfaceDescription.Member serverUpdateMember = testIntf.GetMember("serverUpdate");
    sMsgBus.UnregisterSignalHandler(SignalHandler, serverUpdateMember, null);
    serverUpdateMember = null;
    sJoinCalled = false;
    return true;
}

public static bool ConnectToFoundName(string name) {
    if (sJoinComplete) DisconnectFromFoundName();
    if (sessionListener != null) {
        sMsgBus.SetSessionListener(null, sSessionId);
        sessionListener = null;
    }
    sessionListener = new MySessionListener();
    connectedServerName = name;
    sJoinCalled = true;
    sMsgBus.JoinSession(name, SERVICE_PORT, sessionListener, out sSessionId, opts);
    sJoinComplete = true;
    return true;
}

public static bool StartServer(string name) {
    serverName = name;
    sMsgBus = new AllJoyn.BusAttachment("myApp", true);
    sMsgBus.CreateInterface(INTERFACE_NAME, AllJoyn.InterfaceDescription.SecurityPolicy.Off, out testIntf);
    testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "cat", "ss", "s", "inStr1,inStr2,outStr");
    testIntf.AddSignal("serverUpdate", "s", "json", 0);
    testIntf.Activate();
    sBusListener = new MyBusListener();
    sMsgBus.RegisterBusListener(sBusListener);
    testObj = new TestBusObject(sMsgBus, SERVICE_PATH);
    sMsgBus.Start();
    sMsgBus.RegisterBusObject(testObj);
    for (int i = 0; i < connectArgs.Length; ++i) {
        status = sMsgBus.Connect(connectArgs[i]);
        if (status) {
            connectedVal = connectArgs[i];
            break;
        }
    }
    sMsgBus.RequestName ...
(more)
edit retag flag offensive close merge delete

Comments

The Unity language binding is deprecated and not being well maintained at this time. There is a chat sample that allows for the start/stop that you mention, can you reproduce this in that sample?

bspencer ( 2014-08-19 10:59:57 -0700 )edit

Hi, thanks for your answer, yes I can, it's hard to say exactly when it happens though. I ran two instances on my Android 4.2.1 HTC Desire 500. When I connect them together and then just spend couple of seconds by randomly clicking stop, start and the "join" button, after a while, it crashes.

riko642 ( 2014-08-28 15:14:24 -0700 )edit

I know it's something that a normal user is very unlikely to do, but I just want to make sure that it can't happen after a few starts and stops. If you connect two instances of the chat app, and spend up to 1 min by clicking the buttons, you should get the same error. Hope this helped.

riko642 ( 2014-08-28 15:17:49 -0700 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-09-03 00:42:34 -0700

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi Riko642,

The AllJoyn Unity extension is legacy software and not currently being maintained by anyone in the AllSeen Alliance. You, or anyone else, is welcome to pick up this part of the open source project and help improve the binding to allow for a more rigorous use of bind/unbind of a session in quick succession. As of now can you please file this as a bug in the AllSeen Jira.

Thanks

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-08-03 14:42:15 -0700

Seen: 429 times

Last updated: Sep 03 '14