diff --git a/src/gu/pspgu.h b/src/gu/pspgu.h index eeac81d5..95bba994 100644 --- a/src/gu/pspgu.h +++ b/src/gu/pspgu.h @@ -779,8 +779,10 @@ void sceGuBeginObject(int vtype, int count, const void* indices, const void* ver /** * End conditional rendering of object + * + * @return 0 for success, < 0 for failure **/ -void sceGuEndObject(void); +int sceGuEndObject(void); /** * Enable or disable GE state diff --git a/src/gu/sceGuEndObject.c b/src/gu/sceGuEndObject.c index 42fa58b1..0f3db5d3 100644 --- a/src/gu/sceGuEndObject.c +++ b/src/gu/sceGuEndObject.c @@ -8,16 +8,30 @@ #include "guInternal.h" -void sceGuEndObject(void) +#define ERROR_NOT_FOUND 0x80000025 + +int sceGuEndObject(void) { - // rewrite commands from sceGuBeginObject() + int res; + + gu_object_stack_depth--; + if (gu_object_stack_depth < 0) { + return -ERROR_NOT_FOUND; + } unsigned int *current = gu_list->current; - gu_list->current = gu_object_stack[gu_object_stack_depth - 1]; + gu_list->current = gu_object_stack[gu_object_stack_depth]; sendCommandi(BASE, (((unsigned int)current) >> 8) & 0xf0000); sendCommandi(BJUMP, (unsigned int)current); gu_list->current = current; - gu_object_stack_depth--; + if (gu_curr_context == GU_DIRECT) { + res = _sceGuUpdateStallAddr(); + if (res < 0) { + return res; + } + } + + return gu_object_stack_depth; }