Problem with box context in a callback method

Making & changing box plugins and external apps
Post Reply
bpayan
Posts: 46
Joined: Fri Jan 08, 2010 4:02 pm

Problem with box context in a callback method

Post by bpayan »

Dear Openviber

I received a private message by Aaron and I think this problem can be seen by other Openviber. That's why I post this solution.
Aaron wrote:Hello Baptiste

I'm having another small issue. Every time Gtk's key-release-event is invoked in my box, OpenViBE-designer crashes. When I comment the first line the designer doesn't crash, but of course nothing happens. The processClock and process-routines don't cause any problems I guess because when I hook up a "Stimulation listener" to my box, it seems that stimulations are successfully sent. The other Gtk-related methods work as well because the user interface loads successfully. My conclusion is that something goes wrong in the code snippet posted below:

Code: Select all

gboolean ResponseAndInteractionErrorDetection_keyReleased( GtkWidget* widget, GdkEventKey* event, gpointer data )
{    
    reinterpret_cast<CBoxAlgorithmResponseAndInteractionErrorDetection*>(data)->keyReleased(event->keyval);
    return true;
}
I guess that when this problem is solved, my paradigm will be finished, so I really hope you can help me out.

Greetings

Aaron
The real problem is in the method keyReleased. You try to use information of the context box, but these information are not valid when you call this method.

Code: Select all

boolean CBoxAlgorithmResponseAndInteractionErrorDetection::keyReleased( guint keycode ) 
{ 
    uint64  l_uint64ReleasedKey = keycode;
    boolean  l_bInvokeInteractionError = invokeInteractionError();
    uint64 l_ui64CurrentTime = this->getPlayerContext().getCurrentTime(); 

    this->getLogManager() << LogLevel_Info << "Key pressed" << l_uint64ReleasedKey << "\n"; 
    if ( l_uint64ReleasedKey == KEY_RED )
    {
        setBorder(m_uint64CurrentSquare, COLOR_RED);
        m_vPendingStimulationSet.appendStimulation(OVTK_StimulationId_KeyPressedRed, l_ui64CurrentTime, 0);
    }

} 
You can use information of the context box only during the execution of each type of "process" methods ("process", "processInput", "processClock",...). That's why openvibe crash when you released a key because you are in a gtk "callback" method.

The general strategy use, is to save information of your "callbacks" and use it in the next call of the method "process"
Example of solution:

Code: Select all

#define KEY_NONE -1

gboolean ResponseAndInteractionErrorDetection_keyReleased( GtkWidget* widget, GdkEventKey* event, gpointer data )
{    
    reinterpret_cast<CBoxAlgorithmResponseAndInteractionErrorDetection*>(data)->keyReleased(event->keyval);
    return true;
}

boolean CBoxAlgorithmResponseAndInteractionErrorDetection::keyReleased( guint keycode ) 
{ 
    m_uint64ReleasedKey = keycode;
} 

boolean CBoxAlgorithmResponseAndInteractionErrorDetection::process(void)
{
…
	if(m_uint64ReleasedKey != KEY_NONE)
	{
		boolean  l_bInvokeInteractionError = invokeInteractionError();
		uint64 l_ui64CurrentTime = this->getPlayerContext().getCurrentTime(); 

		this->getLogManager() << LogLevel_Info << "Key pressed" << l_uint64ReleasedKey << "\n"; 
		if ( m_uint64ReleasedKey == KEY_RED )
		{
			setBorder(m_uint64CurrentSquare, COLOR_RED);
			m_vPendingStimulationSet.appendStimulation(OVTK_StimulationId_KeyPressedRed, l_ui64CurrentTime, 0);
		}
		m_uint64ReleasedKey = KEY_NONE;
	}
…
}
I hope this explication is clear. Thanks to Aaron to let me use a part of his code for this example.

Baptiste

Post Reply