MATLAB: Matlab fails to draw figures beyond a certain size

figurehigh resolutionhigh-dpiMATLABopengl

I've begun using a high-resolution screen (3840×2160). When I use the matlab commands
figure
axes
it creates a small figure, with blank axes. If I resize the figure window, to more than about 1/4 of the screen size (for example, by dragging, or by clicking the maximise icon) then the Command Window fills with error messages, and the axes disappear – all that remains is a large grey box and the matlab controls and menu bar.
The error is as follows:
figure
axes
Caught subsequent GLException: GLContext.release(false) during GLDrawableImpl.contextMadeCurrent(this, false) on thread AWT-EventQueue-0
javax.media.opengl.GLException: GLContext.release(false) during GLDrawableImpl.contextMadeCurrent(this, false)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:389)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:337)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1292)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1131)
at javax.media.opengl.awt.GLJPanel$OffscreenBackend.doPaintComponent(GLJPanel.java:2024)
at javax.media.opengl.awt.GLJPanel.paintComponent(GLJPanel.java:569)
at com.mathworks.hg.peer.JavaSceneServerGLJPanel.paintComponent(JavaSceneServerGLJPanel.java:147)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1100(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: javax.media.opengl.GLException: Front colorbuffer is null: samples 0, ResizeableImpl[Initialized true, realized true, texUnit 0, samples 0,
Factory jogamp.opengl.x11.glx.X11GLXDrawableFactory@50eeb7a1,
Handle 0x5000034,
Caps GLCaps[glx vid 0x8b, fbc 0x8b: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, one, mono , hw, GLProfile[GL2/GL2.sw], offscr[fbo]],
fboI back 0, front 0, num 1,
FBO front read 2, FBO[name r/w 2/2, init true, bound false, size 2120x1311, samples 0/0, modified true/true, depth null, stencil null, colorbuffer attachments: 0/1, with 0 textures: [null], msaa[null, hasSink false, dirty true], state FBO missing attachment, obj 0x14061913],
FBO back write 2, FBO[name r/w 2/2, init true, bound false, size 2120x1311, samples 0/0, modified true/true, depth null, stencil null, colorbuffer attachments: 0/1, with 0 textures: [null], msaa[null, hasSink false, dirty true], state FBO missing attachment, obj 0x14061913],
Surface WrappedSurface[ displayHandle 0x7f659ce57470
, surfaceHandle 0x5000034
, size 2120x1311
, UOB[ OWNS_SURFACE | OWNS_DEVICE | WINDOW_INVISIBLE ]
, X11GLXGraphicsConfiguration[X11GraphicsScreen[X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x7f659ce57470, owner true, ResourceToolkitLock[obj 0x611c2515, isOwner true, <7ec6b781, 2839b72d>[count 1, qsz 0, owner <AWT-EventQueue-0>]]], idx 0], visualID 0x8b, fbConfigID 0x8b,
requested GLCaps[rgba 8/8/8/1, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/8, sample-ext default, one, mono , hw, GLProfile[GL2/GL2.sw], on-scr[.]],
chosen GLCaps[glx vid 0x8b, fbc 0x8b: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, one, mono , hw, GLProfile[GL2/GL2.sw], offscr[fbo]]]
, surfaceLock <6528fffc, 66be2d46>[count 1, qsz 0, owner <AWT-EventQueue-0>]
, X11DummyUpstreamSurfaceHook[pixel 2120x1311]
, upstreamSurface false ]]
at jogamp.opengl.GLFBODrawableImpl.swapFBOImpl(GLFBODrawableImpl.java:463)
at jogamp.opengl.GLFBODrawableImpl.contextMadeCurrent(GLFBODrawableImpl.java:408)
at jogamp.opengl.GLContextImpl.contextMadeCurrent(GLContextImpl.java:796)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:365)
... 37 more
Does anyone know how I might go about fixing this?

Best Answer

Replacing the link in <matlab-dir>/sys/os/glnxa64/ to libstdc++.so.6 allowed hardware opengl to be used again - this changed the max texture size from 2048 to 16384.
Clues provided by
opengl info
This initially informed me that Matlab was using software opengl. It also listed the 'MaxTextureSize' at just 2048.
$ OPENGL_DEBUG=verbose <matlab-dir>/bin/glnxa64/need_softwareopengl
libGL: OpenDriver: trying /usr/lib64/dri/tls/nouveau_dri.so
libGL: OpenDriver: trying /usr/lib64/dri/nouveau_dri.so
libGL: dlopen /usr/lib64/dri/nouveau_dri.so failed (<matlab-dir>/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib64/dri/nouveau_dri.so))
libGL error: unable to load driver: nouveau_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: nouveau
libGL: OpenDriver: trying /usr/lib64/dri/tls/swrast_dri.so
libGL: OpenDriver: trying /usr/lib64/dri/swrast_dri.so
libGL: dlopen /usr/lib64/dri/swrast_dri.so failed (<matlab-dir>/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/lib64/dri/swrast_dri.so))
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
This shows the reason that hardware opengl was not used by Matlab.
Going to the specified folder (../../sys/os/) shows both a file and a link to the same file, for an older version of libstdc++.so
The graphics drivers (in particular, nouveau) have been compiled with a newer libstdc++.so.
The commands
$ unlink libstdc++.so
$ ln -sv /usr/lib64/libstdc++.so.6 .
executed within the <matlab-dir>/sys/os/glnxa64/ directory allow Matlab to use the hardware opengl.
MaxTextureSize became 16384, and now the figure can be made full screen with no issues.
Related Question