Problem with box context in a callback method
Posted: Fri Sep 10, 2010 8:55 am
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.
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:
I hope this explication is clear. Thanks to Aaron to let me use a part of his code for this example.
Baptiste
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.
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.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:I guess that when this problem is solved, my paradigm will be finished, so I really hope you can help me out.Code: Select all
gboolean ResponseAndInteractionErrorDetection_keyReleased( GtkWidget* widget, GdkEventKey* event, gpointer data ) { reinterpret_cast<CBoxAlgorithmResponseAndInteractionErrorDetection*>(data)->keyReleased(event->keyval); return true; }
Greetings
Aaron
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);
}
}
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;
}
…
}
Baptiste