@@ -523,14 +523,6 @@ Boolean MCScreenDC::wait(real8 duration, Boolean dispatch, Boolean anyevent)
523523 else if (!done && eventtime > curtime)
524524 t_sleep = MCMin (eventtime - curtime, exittime - curtime);
525525
526- // MM-2015-06-05: [[ MobileSockets ]] Poll sockets.
527- if (MCS_poll (0.0 , 0.0 ))
528- {
529- if (anyevent)
530- done = True;
531- t_sleep = 0.0 ;
532- }
533-
534526 // At this point we yield to android, requesting that we get control back
535527 // within the specified time.
536528 bool t_broken;
@@ -1415,8 +1407,7 @@ static void co_yield_to_android(void)
14151407static bool co_yield_to_android_and_wait (double p_sleep, bool p_wake_on_event)
14161408{
14171409 s_schedule_wakeup = true ;
1418- // MM-2015-06-08: [[ MobileSockets ]] The duration is passed in in milliseconds, not seconds.
1419- s_schedule_wakeup_timeout = (uint32_t )(p_sleep);
1410+ s_schedule_wakeup_timeout = (uint32_t )(p_sleep * 1000.0 );
14201411 s_schedule_wakeup_breakable = p_wake_on_event;
14211412 co_yield_to_android ();
14221413 s_schedule_wakeup = false ;
@@ -1438,7 +1429,13 @@ void MCAndroidBreakWait(void)
14381429{
14391430 // MM-2015-06-08: [[ MobileSockets ]] Make sure we execute on the UI thread.
14401431 // Calling scheduleWakeUp indirectly has this effect.
1441- s_android_ui_env -> CallVoidMethod (s_android_view, s_schedule_wakeup_method, 0 , s_schedule_wakeup_breakable);
1432+ s_schedule_wakeup_was_broken = true ;
1433+ JNIEnv *t_env;
1434+ t_env = MCJavaGetThreadEnv ();
1435+ if (t_env != nil)
1436+ t_env -> CallVoidMethod (s_android_view, s_schedule_wakeup_method, 0 , s_schedule_wakeup_breakable);
1437+ else
1438+ s_android_ui_env -> CallVoidMethod (s_android_view, s_schedule_wakeup_method, 0 , s_schedule_wakeup_breakable);
14421439}
14431440
14441441struct MCAndroidEngineCallThreadContext
@@ -1977,7 +1974,7 @@ JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doProcess(JNIEnv *env, job
19771974 if (!s_engine_running)
19781975 return ;
19791976
1980- s_schedule_wakeup_was_broken = !timedout;
1977+ s_schedule_wakeup_was_broken = !timedout || s_schedule_wakeup_was_broken ;
19811978 co_yield_to_engine ();
19821979}
19831980
@@ -2848,5 +2845,20 @@ JNIEnv *MCJavaGetThreadEnv()
28482845 return t_env;
28492846}
28502847
2848+ JNIEnv *MCJavaAttachCurrentThread ()
2849+ {
2850+ JNIEnv *t_env;
2851+ t_env = nil;
2852+ if (s_java_vm -> AttachCurrentThread (&t_env, nil) < 0 )
2853+ return nil;
2854+ return t_env;
2855+ }
2856+
2857+ void MCJavaDetachCurrentThread ()
2858+ {
2859+ s_java_vm -> DetachCurrentThread ();
2860+ }
2861+
2862+
28512863// //////////////////////////////////////////////////////////////////////////////
28522864
0 commit comments