Bug? MouseEvent problem when converted as object

jmon

Well-Known Member
Licensed User
Hello,

I encountered a problem today, very easy to reproduce.

I'm trying to pass a mouseEvent object through an intermediary function that will call a CallSub. I get a crash, that says that the receiving event doesn't match signature:
Program started.
main._calleventcustom (java line: 67)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: Sub mybtn_clicked signature does not match expected signature.
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:455)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:416)
at b4j.example.main._calleventcustom(main.java:67)
at b4j.example.main._btn_mouseclicked(main.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:64)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3471)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3399)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3767)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$101/10156683.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:927)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/11714529.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub mybtn_clicked signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:446)
... 43 more
Caused by: java.lang.Exception: Sub mybtn_clicked signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:95)
... 44 more
This is the code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
    MainForm.Show       
End Sub

Sub btn_MouseClicked (EventData As MouseEvent)   
    CallEventCustom("myBtn_Clicked", EventData) '<Calling a custom call sub function, try to pass the mouseevent
End Sub

Private Sub CallEventCustom(EventName As String, Argument As Object)
    CallSub2(Me, EventName, Argument)'<Calling a custom call sub function
End Sub

Sub myBtn_Clicked(EventData As MouseEvent)'<crash here!
    Log($"Mouseclicks : ${EventData.ClickCount}"$)
End Sub
I've included an example. What is the problem there?

Thanks.
jmon.
 

Attachments

Erel

Administrator
Staff member
Licensed User
You will need to change your code to:
B4X:
Sub myBtn_Clicked(EventDataObj As Object)
   Dim EventData As MouseEvent = EventDataObj
   Log($"Mouseclicks : ${EventData.ClickCount}"$)
End Sub
MouseEvent is a wrapped object. When you convert it to Object, the compiler unwraps it automatically.

Later when you call the second sub with CallSub the compiler cannot know that it needs to wrap it again so you get the error.
 
Top