OpenGL pyramid project run-time error on Xcode cocoa Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
roger1318
In need of some credit
In need of some credit
Posts: 2
Joined: Mon May 13, 2019 2:59 am

OpenGL pyramid project run-time error on Xcode cocoa

Post by roger1318 »

Hi folks, I have been trying to build the opengl sample project with our latest release 3.1.2 on multiple platforms. Windows and Linux have worked out perfectly well, but macOS has seen some setbacks.

Everything compiles OK, but upon running and seeing a flash of the GL window, there pops up a run-time error at void MyGLCanvas::OnPaint(...) at line SwapBuffers(), and the error is Thread 1: EXC_BAD_ACCESS (code=1, address=0x1082cf000). Step into one level down to glcanvas.mm, and it's the objective-c line "[context flushBuffer] causing all the grief. Beyond there is the assembly code which doesn't make a whole lot sense to me, but I still copy paste it down below. Toggling between dynamic/static, 64/32bit doesn't make a difference.

Has anyone run into this issue as well? The other OpenGL samples, isosurf, penguin and cube all work fine. Unfortunately, the pyramid example is so important since it's the only one that uses the modern opengl standards. My guess is somehow the OpenGL 3.2 render context got corrupted or not set properly. I would greatly appreciate it if anybody can give me heads up in fixing this problem.

======================= Basic setup ===================
wxWidgets version: 3.1.2
Platform: MacOS High Sierra 10.13.5
Xcode version: 9.4.1
Build: dynamic/static with 64bit/32bit all tried

==================== pyramid.cpp =======================
void MyGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
// This is a dummy, to avoid an endless succession of paint messages.
// OnPaint handlers must always create a wxPaintDC.
wxPaintDC dc(this);
// Avoid painting when we have not yet a size
if ( m_winHeight < 1 || !m_oglManager )
return;
// This should not be needed, while we have only one canvas
SetCurrent(*m_oglContext);
// Do the magic
m_oglManager->Render();
SwapBuffers(); >>>> Thread 1: EXC_BAD_ACCESS (code=1, address=0x106665000)
}

==================== glcanvas.mm =======================
bool wxGLCanvas::SwapBuffers()
{
WXGLContext context = WXGLGetCurrentContext();
wxCHECK_MSG(context, false, wxT("should have current context"));
[context flushBuffer]; >>>>> Thread 1: EXC_BAD_ACCESS (code=1, address=0x106665000)
return true;
}

================= Assembly code ====================
0x7fff40f4139c <+11>: movq 0x5c2f40f5(%rip), %rax ; NSOpenGLContext._CGLContext
0x7fff40f413a3 <+18>: movq (%rdi,%rax), %rdi
0x7fff40f413a7 <+22>: callq 0x7fff418474f4 ; symbol stub for: CGLFlushDrawable
0x7fff40f413ac <+27>: movl %eax, %ebx
0x7fff40f413ae <+29>: testl %ebx, %ebx
0x7fff40f413b0 <+31>: je 0x7fff40f413f9 ; <+104>
0x7fff40f413b2 <+33>: movq 0x5c2e7b57(%rip), %r14 ; (void *)0x00007fff9d8ec2e0: NSException
0x7fff40f413b9 <+40>: movl %ebx, %edi
0x7fff40f413bb <+42>: callq 0x7fff418474ee ; symbol stub for: CGLErrorString
0x7fff40f413c0 <+47>: movq 0x5bfaefc1(%rip), %rcx ; (void *)0x00007fff9d7ed8f0: NSGenericException
0x7fff40f413c7 <+54>: movq (%rcx), %rdx
0x7fff40f413ca <+57>: movq 0x5c2b2f6f(%rip), %rsi ; "raise:format:"
0x7fff40f413d1 <+64>: movq %rax, 0x8(%rsp)
0x7fff40f413d6 <+69>: movl %ebx, (%rsp)
0x7fff40f413d9 <+72>: leaq 0x5c02b680(%rip), %rcx ; @"%s failed in %s due to error %d (%s)"
0x7fff40f413e0 <+79>: leaq 0x95fc33(%rip), %r8 ; "-[NSOpenGLContext flushBuffer]"
0x7fff40f413e7 <+86>: leaq 0x95fc4b(%rip), %r9 ; "CGLFlushDrawable"
0x7fff40f413ee <+93>: xorl %eax, %eax
0x7fff40f413f0 <+95>: movq %r14, %rdi
0x7fff40f413f3 <+98>: callq *0x5bfb0d6f(%rip) ; (void *)0x00007fff6a8b9e80: objc_msgSend
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: OpenGL pyramid project run-time error on Xcode cocoa

Post by Manolo »

Platform: MacOS High Sierra 10.13.5
Can you try a different [higher] version?
I don't have a Mac, but I've read somewhere about some wrong OpenGL stuff in some OSX versions.
roger1318
In need of some credit
In need of some credit
Posts: 2
Joined: Mon May 13, 2019 2:59 am

Re: OpenGL pyramid project run-time error on Xcode cocoa

Post by roger1318 »

Manolo wrote: Mon May 13, 2019 12:03 pm
Platform: MacOS High Sierra 10.13.5
Can you try a different [higher] version?
I don't have a Mac, but I've read somewhere about some wrong OpenGL stuff in some OSX versions.
Hey Manolo, thanks so much for the tip!

It's working with macOS 10.14.0 and Xcode 10.1. I am surprised it works even without adding any OpenGL framework to the project.
Post Reply