summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike <contact@mikelittman.me>2026-10-05 01:47:40 -0500
committerGitHub <noreply@github.com>2026-10-05 14:47:40 +0800
commitdcaa2903c3bb96e97bf679d0a721536aaa019a29 (patch)
treed41feecf98a8d4b6aa812e47b5304209aa183703
parent62e2d529558ba086708025b394aa790e49076c77 (diff)
Avoid the Apple OpenGL null-fence crash during precache (#30)
glDeleteBuffers and glWaitSync on a failed fence both fault in GLDFenceRec::getStatus on Apple's GL/Metal translator. Finish and unbind before deleting buffers, skip a null upload fence, and resize depth targets with the unsized format Apple accepts.
-rw-r--r--indra/llrender/llimagegl.cpp48
-rw-r--r--indra/llrender/llrendertarget.cpp10
-rw-r--r--indra/llrender/llvertexbuffer.cpp23
3 files changed, 63 insertions, 18 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 1d51c6741c..82bc00fe7a 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -1839,9 +1839,16 @@ void LLImageGL::syncToMainThread(LLGLuint new_tex_name)
// wait for texture upload to finish before notifying main thread
// upload is complete
auto sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- glFlush();
- glClientWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
- glDeleteSync(sync);
+ if (sync)
+ {
+ glFlush();
+ glClientWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
+ glDeleteSync(sync);
+ }
+ else
+ {
+ glFinish();
+ }
}
else
{
@@ -1851,20 +1858,29 @@ void LLImageGL::syncToMainThread(LLGLuint new_tex_name)
glFlush();
auto sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
glFlush();
- LL::WorkQueue::postMaybe(
- mMainQueue,
- [=]()
- {
- LL_PROFILE_ZONE_NAMED("cglt - wait sync");
- {
- LL_PROFILE_ZONE_NAMED("glWaitSync");
- glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
- }
+ if (sync)
+ {
+ LL::WorkQueue::postMaybe(
+ mMainQueue,
+ [=]()
{
- LL_PROFILE_ZONE_NAMED("glDeleteSync");
- glDeleteSync(sync);
- }
- });
+ LL_PROFILE_ZONE_NAMED("cglt - wait sync");
+ {
+ LL_PROFILE_ZONE_NAMED("glWaitSync");
+ glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
+ }
+ {
+ LL_PROFILE_ZONE_NAMED("glDeleteSync");
+ glDeleteSync(sync);
+ }
+ });
+ }
+ else
+ {
+ // glFenceSync failed. glWaitSync(0) is dispatched to Apple's
+ // OpenGL thread, which faults in GLDFenceRec::getStatus.
+ glFinish();
+ }
}
}
diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp
index ebdc609f94..dcee340a71 100644
--- a/indra/llrender/llrendertarget.cpp
+++ b/indra/llrender/llrendertarget.cpp
@@ -95,7 +95,15 @@ void LLRenderTarget::resize(U32 resx, U32 resy)
{
gGL.getTexUnit(0)->bindManual(mUsage, mDepth);
U32 internal_type = LLTexUnit::getInternalType(mUsage);
- LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false);
+ // Apple's GL rejects sized GL_DEPTH_COMPONENT24 with GL_UNSIGNED_INT.
+#if LL_DARWIN
+ const U32 depth_internal = GL_DEPTH_COMPONENT;
+#else
+ const U32 depth_internal = GL_DEPTH_COMPONENT24;
+#endif
+ glGetError();
+ LLImageGL::setManualImage(internal_type, 0, depth_internal, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false);
+ glGetError();
sBytesAllocated += pix_diff*4;
}
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index 8a73a68c54..a827927809 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -315,7 +315,28 @@ static void delete_buffers(S32 count, GLuint* buffers)
if (!sFreeList[idx].empty())
{
- glDeleteBuffers((GLsizei)sFreeList[idx].size(), sFreeList[idx].data());
+ if (gGLManager.mIsApple)
+ {
+ // Apple's GL/Metal translator crashes in GLDFenceRec::getStatus
+ // (null fence, fault at +0x24) when glDeleteBuffers waits on a
+ // sync that was never created. Unbind and finish first.
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ LLVertexBuffer::sGLRenderBuffer = 0;
+ LLVertexBuffer::sGLRenderIndices = 0;
+ glFinish();
+ for (GLuint name : sFreeList[idx])
+ {
+ if (name)
+ {
+ glDeleteBuffers(1, &name);
+ }
+ }
+ }
+ else
+ {
+ glDeleteBuffers((GLsizei)sFreeList[idx].size(), sFreeList[idx].data());
+ }
sFreeList[idx].resize(0);
}
}