From 0a4046f2bf29072f7169d7f1c48cdf88ef0d8ce5 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Sat, 5 Apr 2014 20:22:19 -0700 Subject: [PATCH] Added safety check to lazyusf for non-working sets; Now they'll fail with a useful error message instead of locking up in an infinite loop --- Frameworks/lazyusf/lazyusf/interpreter_cpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c index 605f65490..4f2283fb4 100644 --- a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c +++ b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c @@ -722,10 +722,23 @@ void ExecuteInterpreterOpCode (usf_state_t * state) { } void StartInterpreterCPU (usf_state_t * state) { + const int safety_count_max = 20000000; + int safety_count = safety_count_max; + size_t last_sample_buffer_count = state->sample_buffer_count; + state->NextInstruction = NORMAL; while(state->cpu_running) { ExecuteInterpreterOpCode(state); + if (!--safety_count) { + if (last_sample_buffer_count == state->sample_buffer_count) { + DisplayError( state, "Emulator core is not generating any samples after 400 million instructions" ); + break; + } else { + safety_count = safety_count_max; + last_sample_buffer_count = state->sample_buffer_count; + } + } } state->cpu_stopped = 1;