From dc25f28774c40155caf300820f0cff40a59bd0f7 Mon Sep 17 00:00:00 2001 From: Shinovon Date: Tue, 22 Jul 2025 10:50:53 +0500 Subject: [PATCH 1/2] Check glGetError after glBufferData --- misc/opengl/GLCommon.h | 2 ++ src/Game.h | 2 ++ src/Graphics_GL1.c | 3 ++- src/Graphics_GL11.c | 3 ++- src/Graphics_GL2.c | 3 ++- src/_GLShared.h | 10 ++++++++++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/misc/opengl/GLCommon.h b/misc/opengl/GLCommon.h index 525db8fc5..9c8b6f0ee 100644 --- a/misc/opengl/GLCommon.h +++ b/misc/opengl/GLCommon.h @@ -106,3 +106,5 @@ typedef cc_uintptr GLpointer; #define GL_COMPILE_STATUS 0x8B81 #define GL_LINK_STATUS 0x8B82 #define GL_INFO_LOG_LENGTH 0x8B84 + +#define GL_OUT_OF_MEMORY 0x0505 diff --git a/src/Game.h b/src/Game.h index 867f59c52..f1b9a7bcc 100644 --- a/src/Game.h +++ b/src/Game.h @@ -39,6 +39,8 @@ extern cc_string Game_Mppass; #if defined CC_BUILD_N64 || defined CC_BUILD_PS1 || defined CC_BUILD_SATURN #define DEFAULT_VIEWDIST 20 +#elif defined CC_BUILD_SYMBIAN + #define DEFAULT_VIEWDIST 64 #elif defined CC_BUILD_NDS #define DEFAULT_VIEWDIST 192 #else diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index c7189dcd5..f9c9fd739 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -146,8 +146,9 @@ void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) { return FastAllocTempMem(count * strideSizes[fmt]); } -void Gfx_UnlockVb(GfxResourceID vb) { +static cc_bool UnlockVb(GfxResourceID vb) { _glBufferData(GL_ARRAY_BUFFER, tmpSize, tmpData, GL_STATIC_DRAW); + return _glGetError() != GL_OUT_OF_MEMORY; } diff --git a/src/Graphics_GL11.c b/src/Graphics_GL11.c index 81226ec37..60a75cc58 100644 --- a/src/Graphics_GL11.c +++ b/src/Graphics_GL11.c @@ -91,8 +91,9 @@ void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) { return FastAllocTempMem(count * strideSizes[fmt]); } -void Gfx_UnlockVb(GfxResourceID vb) { +static cc_bool UnlockVb(GfxResourceID vb) { UpdateDisplayList(ptr_to_uint(vb), tmpData, tmpFormat, tmpCount); + return true; } GfxResourceID Gfx_CreateVb2(void* vertices, VertexFormat fmt, int count) { diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index 4eefa9174..d40cf8349 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -118,8 +118,9 @@ void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) { return FastAllocTempMem(count * strideSizes[fmt]); } -void Gfx_UnlockVb(GfxResourceID vb) { +static cc_bool UnlockVb(GfxResourceID vb) { glBufferData(GL_ARRAY_BUFFER, tmpSize, tmpData, GL_STATIC_DRAW); + return glGetError() != GL_OUT_OF_MEMORY; } diff --git a/src/_GLShared.h b/src/_GLShared.h index 978de97ec..40c2afa65 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -419,3 +419,13 @@ void Gfx_SetScissor(int x, int y, int w, int h) { _glScissor(x, Game.Height - h - y, w, h); } + +static cc_bool UnlockVb(GfxResourceID vb); + +void Gfx_UnlockVb(GfxResourceID vb) { + for (;;) { + if (UnlockVb(vb)) return; + + if (!Game_ReduceVRAM()) Process_Abort("Out of video memory! (updating static VB)"); + } +} From d05f5cc34dfc045161b3b44a824a60926720e50c Mon Sep 17 00:00:00 2001 From: Shinovon Date: Tue, 22 Jul 2025 13:09:18 +0500 Subject: [PATCH 2/2] Check glGetError only on Symbian --- src/Graphics_GL1.c | 4 ++++ src/Graphics_GL2.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index f9c9fd739..02a21331c 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -148,7 +148,11 @@ void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) { static cc_bool UnlockVb(GfxResourceID vb) { _glBufferData(GL_ARRAY_BUFFER, tmpSize, tmpData, GL_STATIC_DRAW); +#if defined CC_BUILD_SYMBIAN return _glGetError() != GL_OUT_OF_MEMORY; +#else + return true; +#endif } diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index d40cf8349..1803597e8 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -120,7 +120,11 @@ void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) { static cc_bool UnlockVb(GfxResourceID vb) { glBufferData(GL_ARRAY_BUFFER, tmpSize, tmpData, GL_STATIC_DRAW); +#if defined CC_BUILD_SYMBIAN return glGetError() != GL_OUT_OF_MEMORY; +#else + return true; +#endif }