From 697b50c3ff1b0d179c5862efa56cb19fa640824c Mon Sep 17 00:00:00 2001
From: Tony Wasserka <NeoBrainX@gmail.com>
Date: Sat, 23 Aug 2014 14:14:34 +0200
Subject: [PATCH] Pica/VertexShader: Fix a bug in the call stack handling.

---
 src/video_core/vertex_shader.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/video_core/vertex_shader.cpp b/src/video_core/vertex_shader.cpp
index cdecbff3c7..db8244317c 100644
--- a/src/video_core/vertex_shader.cpp
+++ b/src/video_core/vertex_shader.cpp
@@ -191,8 +191,9 @@ static void ProcessShaderCode(VertexShaderState& state) {
                 if (*state.call_stack_pointer == VertexShaderState::INVALID_ADDRESS) {
                     exit_loop = true;
                 } else {
-                    state.program_counter = &shader_memory[*state.call_stack_pointer--];
-                    *state.call_stack_pointer = VertexShaderState::INVALID_ADDRESS;
+                    // Jump back to call stack position, invalidate call stack entry, move up call stack pointer
+                    state.program_counter = &shader_memory[*state.call_stack_pointer];
+                    *state.call_stack_pointer-- = VertexShaderState::INVALID_ADDRESS;
                 }
 
                 break;