Skip to content

Commit 3029308

Browse files
committed
Fix timers.
1 parent b3e9b95 commit 3029308

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

plugins/media/media.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,16 @@ void ctr_internal_media_recalcy(int oldWindowHeight) {
12081208
}
12091209
}
12101210

1211+
void ctr_internal_media_update_timers(ctr_object* media) {
1212+
for(int i = 1; i <= CtrMaxMediaTimers; i++) {
1213+
if (CtrMediaTimers[i] < 0) continue;
1214+
if (CtrMediaTimers[i] == 0) {
1215+
ctr_media_event_timer(media, CTR_DICT_ON_TIMER, i);
1216+
}
1217+
CtrMediaTimers[i]--;
1218+
}
1219+
}
1220+
12111221
/**
12121222
* @def
12131223
* [ Media ] screen: [ Text ]
@@ -1296,15 +1306,6 @@ ctr_object* ctr_media_screen(ctr_object* myself, ctr_argument* argumentList) {
12961306
SDL_RenderCopy(CtrMediaRenderer, texture, &s, &dimensions);
12971307
}
12981308
myself->info.sticky = 1;
1299-
if (CtrMediaEventListenFlagTimer) {
1300-
for(int i = 1; i <= CtrMaxMediaTimers; i++) {
1301-
if (CtrMediaTimers[i] < 0) continue;
1302-
if (CtrMediaTimers[i] == 0) {
1303-
ctr_media_event_timer(myself, CTR_DICT_ON_TIMER, i);
1304-
}
1305-
CtrMediaTimers[i]--;
1306-
}
1307-
}
13081309
if (CtrMediaEventListenFlagStep) {
13091310
ctr_send_message(myself, CTR_DICT_ON_STEP, strlen(CTR_DICT_ON_STEP), NULL );
13101311
}
@@ -1313,7 +1314,10 @@ ctr_object* ctr_media_screen(ctr_object* myself, ctr_argument* argumentList) {
13131314
ctr_internal_media_reset();
13141315
return myself;
13151316
}
1317+
//Update timers, both outside and inside event loop (otherwise you could stall it)
1318+
if (CtrMediaEventListenFlagTimer) ctr_internal_media_update_timers(myself);
13161319
while (SDL_PollEvent(&event)) {
1320+
if (CtrMediaEventListenFlagTimer) ctr_internal_media_update_timers(myself);
13171321
player = NULL;
13181322
focusImage = NULL;
13191323
if (controllableObject) {

0 commit comments

Comments
 (0)