tidev / titanium-socketio

Use the native Socket.io SDK's with Axway Titanium.
Apache License 2.0
25 stars 11 forks source link

socket.off(event, function) crash on Android #10

Closed DouglasHennrich closed 4 years ago

DouglasHennrich commented 5 years ago
...
socket.on(`requestHoist:${requestHoistId}:accept`, requestCatched)

...
// Later on requestCatched
socket.off(`requestHoist:${requestHoistId}:accept`, requestCatched)

I'm getting this error on terminal:

[ERROR] TiExceptionHandler: (main) [122890,125713]     socket.off(`requestHoist:${requestHoistId}:accept`, requestCatched);
[ERROR] TiExceptionHandler:            ^
[ERROR] TiExceptionHandler: Error: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.Reference.get()' on a null object reference
[ERROR] TiExceptionHandler:     at SocketIOClient.requestCatched (eval at Module._compile (/app.js:728:13), <anonymous>:427:12)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     com.appc.titanium.socketio.SocketIOClientProxy.off(SocketIOClientProxy.java:115)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:55)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Function.handleMessage(V8Function.java:80)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:101)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:164)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:6541)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[ERROR] TiExceptionHandler:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
[ERROR] V8Exception: Exception occurred at undefined:427: Uncaught Error: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.Reference.get()' on a null object reference

Module version: 1.0.2 TiSDK: 7.4.2.GA

janvennemann commented 5 years ago

Please check the new 2.0.0 release which should fix this issue.

DouglasHennrich commented 5 years ago

Hello @janvennemann I just tested the version 2.0.0 and I can't use socket.off() like iOS, to remove all listeners:

[ERROR] TiExceptionHandler: (main) [100457,102056] /alloy/controllers/private/user/home.js:184
[ERROR] TiExceptionHandler:       socket.off();
[ERROR] TiExceptionHandler:              ^
[ERROR] TiExceptionHandler: Uncaught off: Invalid number of arguments. Expected 2 but got 0
[ERROR] TiExceptionHandler:     at removeSocket(/alloy/controllers/private/user/home.js:184:14)
[ERROR] TiExceptionHandler:     at Alloy.Models.user.Logout(/alloy/controllers/private/user/home.js:300:9)
[ERROR] TiExceptionHandler:     at Logout(/alloy/models/User.js:99:5)
[ERROR] TiExceptionHandler:     at onClick(/alloy/controllers/private/user/home.js:299:25)
[ERROR] TiExceptionHandler:     at btn.addEventListener.event(/alloy/widgets/dhennrich.navBar/controllers/widget.js:164:21)
[ERROR] TiExceptionHandler:     at value(ti:/events.js:49:21)
[ERROR] TiExceptionHandler:     at value(ti:/events.js:101:19)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:63)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:971)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1196)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:401)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:101)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:164)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:6541)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[ERROR] V8Exception: Exception occurred at /alloy/controllers/private/user/home.js:184: Uncaught off: Invalid number of arguments. Expected 2 but got 0
[ERROR] V8Exception: off: Invalid number of arguments. Expected 2 but got 0
janvennemann commented 4 years ago

We just released new version of the socket.io module that finally fixes this issue on Android. Sorry for the huge delay, i was assigned to other projects in the meantime and totally lost track of this. I hope the fixed module can be of use in future projects.