Java Question Events from a non-UI thread and debugger(s) behaviour

JordiCP

Expert
Licensed User
Longtime User
I am confused, and don't know where I can be wrong.

Using my OpenCV lib, now I am translating some examples that I wrote using cameraEx, to JavaCameraView.

This class is executing some tasks on a different thread, with a Runnable.
From there, it raises an event. The called B4A Sub, will be executed in the same thread (non-UI) as the caller. I have added @RaisesSynchronousEvents before the "run()" in the Runnable.
A parameter is passed to the Sub, and the Sub modifies it in-place
Then, when the B4A Sub returns, the result is drawn into a surfaceView

There are some strange behaviours
  • In release mode, it works correctly.--> OK
  • In legacy debug mode, it also works, but if I put a breakpoint in the Sub, it crashes --> I think it is normal, and even think that I read about it somewhere, but can't remember where (if there is a post about it, please can someone give me the link?) --> so, let's assume that OK
  • But rapid debug mode, even if without breakpoints, it works desynchronized (image has blinks and offsets). Also, operations are not performed (the shown result is the same as the original parameter, so it is as if it wasn't modified at all). This time I can place breakpoints in the Sub, but it seems as if in-place modifications are not working

My question: am I doing something wrong or is there any workaround?
 

JordiCP

Expert
Licensed User
Longtime User
More info, more tests.

I changed the signature and instead of modifying the object instance passed as a parameter, now it returns a new object

B4X:
   Object r = ba.raiseEvent(this,eventName.toLowerCase()+"_newframe",mFrameChain[1 - mChainIdx]);   // This works, and the BA sub is executed properly
   if ( r!=null && r instanceof Mat )
   {
        Mat m = (Mat) r;
        predispatch(m);
   }

But in rapid debugger, r is always null. (The object returned by the BA Sub is NOT null )

Also have tested with ba.raiseEvent(this,...) and ba.raiseEvent(ba, ....) .....


I think that rapid debugger makes some trick such that passed and return parameters do not synchronize on the other side, so raiseEvent does not behave exactly synchronously. Perhaps it does regarding timing, but not regarding parmeters.
 

JordiCP

Expert
Licensed User
Longtime User
Well, finally I found a simple/dirty/working way to be able to use rapid debugger with events from other threads synchronously

As with rapid debug mode these events in B4A are run in UI thread , I simply leave the calling thread waiting and achieve 'resynchronization' notifying it at the end of my Sub. So, it can't yet work with Subs that return objects, but yes with subs that pass parameters which can be modified from B4A.


Now I feel as clever as this one :D
hack.jpg
 
Top