Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: App stops receiving bps events.

The problem isn't with missing an up or down event but with no longer reciecving any events at all.

This is precisely how the problem manifested when I was making two calls to bps_get_event() in close succession. It was unintuitive to think that all calls would be missed by consuming twice for me as well. You might think you would only process half  the calls but that is not how bps_get_event works.

 

I will try to explain event processing to the best of my understanding: The reason it does not miss only half the calls is because the event generator runs asynchronously with the application, not synchronously. After an event is consumed, the system needs processing time for the next event to be ready to be processed. Even though bps_get_event() is called and there may actually be touch events processed and ready in the queue, it doesn't mean bps_get_event() will return any events. The result is that some calls to bps_get_event() are effectively useless. At least, all this was the understanding I had after fixing my own application. There may even be some documentation somewhere on this, but I have not read it.

 

Question your current understanding of the way bps_get_event works, because in my experience that function didn't work according to intuition. In particular, its behaviour when it is in the state where there are many touch events being made in close succession is somewhat confusing. You are dealing with a concurrent thread/process, and there are many strange things that can happen when dealing with concurrency.  Let me guess, when you make a rapid succession of touch events, it forces you into the state of non-detection quickly, doesn't it? And when you make infrequent touch events, this state doesn't manifest very quickly or doesn't  manifest at all. Am I correct? If so, I am guessing there's a reasonable chance you are over-consuming the events.

 

If you have more than one instance of bps_get_event in your code it could be a sign that you are over-consuming.

 

Scott

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: App stops receiving bps events.

Give people time to respond. There are numerous advisors in the forum that I think are qualified to help, but you posted only on Friday and the weekend has just passed. These people need their weekends!

 

Scott

Developer
Posts: 163
Registered: ‎04-16-2009
My Device: Not Specified

Re: App stops receiving bps events.

Thank you for such a detailed reply.  It's nice to see that I'm not the only one that has had this problem.  First I have searched all my code and I am 100% sure that bps_get_event() is only being called in one spot and screen_stop_events() isn't getting called either.

 

My game is also single thread as is the FallingBlocks demo.  I have an int main() that goes into an infinte loop until a bool is set indicating shut down.  Now I would only assume that there is another thread or interrupt that is handling the events that bps_get_event() returns, but I would assume that bps_get_event() pulls from a queue that use somekind of mutex locking.

 

With all that said, yes my game can call bps_get_event() in rapid succession since the main loop will wait until bps_get_event() returns a NULL event.  Still I'm going to check out all the bps functions I use an perhaps I am using another call that might be calling it indirectly.

 

Here is my current game loop and I have yet to be able to determine what kind of motion causes it.  For all I know it could be me corrupting memory somehow and stomping over bps.  It's times like this I miss Java and yes I never thought I would say that.

 

bool QnxApp::onUpdate()
{
	Logger&	log	= getLogger();

    while( true )
    {
        bps_event_t* event = NULL;

    	bps_get_event( &event, 1 );

        if ( event )
        {
        	int	domain = bps_event_get_domain( event );

        	if ( domain == screen_get_domain() )
        	{
        		handleScreenEvent( event );
        	}
        	else
        	if ( domain == navigator_get_domain() )
        	{
        		handleNavigatorEvent( event );
        	}
        	else
            if ( domain == dialog_get_domain() )
            {
                handleDialogEvent( event );
            }
            else
            {
            	log.verbose( Str( "QnxApp::onUpdate: unknown event domain %d", domain ) );
            }
        }
        else
        {
        	break;
        }
    }

	m_Game.onUpdate();

	return (m_bQuit == false) ? true : false;
}

 

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: App stops receiving bps events.

Try changing your call to bps_get_event to this and add this extra line:

 

        rc = bps_get_event(&event, 50);
        assert(rc == BPS_SUCCESS);

 

Of course, do a generic initialization of "int rc" outside of the while loop

 

The 50 means 50 ms delay. Like I said before, I think bps_get_event may act a little strangely with calls of close succession (or maybe I really don't understand it), so bump it up from your 1 ms to 50 ms. If you give it a negative integer, the call will block until an event is received. If 50 doesn't work, try -1.

 

I think one of those options will solve your problem.

 

Scott

Developer
Posts: 163
Registered: ‎04-16-2009
My Device: Not Specified

Re: App stops receiving bps events.

Wow.  I can't block for that long.  The game needs to run at 30 frames per second, so I only have 33ms as it is.  It killed me to lay the 1ms down Smiley Happy  Still I saw in one of the sources that they needed to add the 1ms until a bug got fix.  Maybe I will have to make my own thread that pulls the events out.  Hmm, maybe I will just bump it to 10ms and see if it goes away.

 

Thanks for the thoughts.

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: App stops receiving bps events.

[ Edited ]

Yeah 50 ms is really long for a game lol. The fact that the source says there's a bug may verify what I've been noticing.

 

At least try the call to assert (I have no idea what that does). Did the source say anything about using -1 to block?

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: App stops receiving bps events.

[ Edited ]
int bps_get_event(bps_event_t **event, int timeout_ms)

Arguments:

event - The event to return. The event is returned through this pointer. In the case of a timeout, NULL is returned. timeout_msAn integer value that defines the timeout: positive: Return when event is available or after 

timeout_ms - milliseconds, whichever occurs first.0: Return immediately.negative: Block until an event is available

If the timeout is 1, 50, or 1000, I don't think it shouldn't have any effect on the responsiveness of your game because the timeout only represents the maximum blocking time. If an event is received,  bps_get_event returns immediately.

 

edit: sorry I thought you were only doing the event handling in the loop, but I see you are also doing m_Game.onUpdate();. I am assuming this updates the sceen and/or game state, and this code can't be blocked. I suppose the solution would be to have a separate thread to handle game-state updates.

Retired
Posts: 3
Registered: ‎10-26-2011
My Device: Bold 9700
My Carrier: Rogers

Re: App stops receiving bps events.

Would it be possible to max out "bps_set_verbosity", reproduce the condition, and then PM the captured logs to me?

Developer
Posts: 163
Registered: ‎04-16-2009
My Device: Not Specified

Re: App stops receiving bps events.

Thank you for the help, I am trying it now.  So far I haven't had the issue.  I switched to my win32 build and managed to find an uninitialized buffer and a couple of other bugs.  The Java version initializes everything so I guess I missed that.  I will try it for the next hour before I call it fixed.

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: App stops receiving bps events.

I feel pathetic now, but that is what happens when you have no experence in some area.

Glad to see that superdirt has had this bug/issue.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.