In my game, I encounter from time to time a very annoying bug as it crashes the app. I use B4A v3.50.
I have two threads in parallel: the libGDX thread and a computation thread. In these two threads, functions are called in Java libraries and some of these functions trigger an event. To trigger these events, I use RaiseEvent2 and not RaiseEventFromDifferentThread because I need speed and, in all computations, my event handler in my B4A code has to return a result.
The problem occurs when I click on one of the active objects on screen during the computation in the background. There are sometimes collisions between events from the different threads and the sender of an event become the sender of the other event, leading to a big failure of my code. The problem is coincidental (most of the time, all works fine) and thus difficult to reproduce. If I ignore the received event with the wrong sender, I also ignore the user action or a computation demand. It's what I'm doing now to avoid crashes but it's not really a workaround (a computation not done has big consequences). I want to find a solution where I don't lose any event.
Could this be fixed with the Synchronized keyword in the RaiseEvent2 declaration?
I have two threads in parallel: the libGDX thread and a computation thread. In these two threads, functions are called in Java libraries and some of these functions trigger an event. To trigger these events, I use RaiseEvent2 and not RaiseEventFromDifferentThread because I need speed and, in all computations, my event handler in my B4A code has to return a result.
The problem occurs when I click on one of the active objects on screen during the computation in the background. There are sometimes collisions between events from the different threads and the sender of an event become the sender of the other event, leading to a big failure of my code. The problem is coincidental (most of the time, all works fine) and thus difficult to reproduce. If I ignore the received event with the wrong sender, I also ignore the user action or a computation demand. It's what I'm doing now to avoid crashes but it's not really a workaround (a computation not done has big consequences). I want to find a solution where I don't lose any event.
Could this be fixed with the Synchronized keyword in the RaiseEvent2 declaration?