OpenGL Rendering in Matlab R2024b on Ubuntu LTS 24.04 fails: com.jogamp​.opengl.GL​Exception: X11GLXDrawableFactory - Could not initialize shared resources for ...

조회 수: 740 (최근 30일)
This error message means that 3D accelerated OpenGL rendering does not work. On same hardware R2024a didn't even try OpenGL, so this is a new problem. This applies to R2024b running on Ubuntu LTS 24.04 on at least two different hardware. There are many more reports here of same errors on older Linux distrubitions with older Matlab versions and probably older hardware, with same workarounds. But it would be better if 3D acceleration worked out of the box with R2024b or at least get disabled by default, if there is a problem.
The whole error message is:
com.jogamp.opengl.GLException: X11GLXDrawableFactory - Could not initialize shared resources for X11GraphicsDevice[type .x11, connection :1, unitID 0, handle 0x0, owner false, ResourceToolkitLock[obj 0x134ee3b8, isOwner false, <590c7f9b, 33bfcb35>[count 0, qsz 0, owner <NULL>]]]
at jogamp.opengl.x11.glx.X11GLXDrawableFactory$SharedResourceImplementation.createSharedResource(X11GLXDrawableFactory.java:326)
at jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:297)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:688)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:580)
at jogamp.opengl.x11.glx.X11GLXDrawableFactory$SharedResourceImplementation.createSharedResource(X11GLXDrawableFactory.java:297)
... 2 more
This happens at least on the following Intel GPUs:
  • Intel Corporation WhiskeyLake-U GT2 [UHD Graphics 620]
  • Intel Corporation Raptor Lake-P [Iris Xe Graphics] (rev 04)
A workaround is to disable 3D acceleration with 'matlab -softwareopengl'.
On a laptop which has both Nvidia and Intel GPU Matlab automatically disables 3D acceleration when you attempt to use the Nvidia GPU:
jjaakkol@lx4-fuxi0:~$ __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia matlab
MATLAB is selecting SOFTWARE rendering.
However if you force 3D rendering on the nvidia GPU, it seems to work fine:
jjaakkol@lx4-fuxi0:~$ __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia matlab -nosoftwareopengl -nodesktop
< M A T L A B (R) >
Copyright 1984-2024 The MathWorks, Inc.
R2024b (24.2.0.2712019) 64-bit (glnxa64)
August 22, 2024
To get started, type doc.
For product information, visit www.mathworks.com.
Warning: OpenGL Startup options will be removed in a future release.
>> rendererinfo
ans =
struct with fields:
GraphicsRenderer: 'OpenGL Hardware'
Vendor: 'NVIDIA Corporation'
Version: '4.6.0 NVIDIA 555.42.06'
RendererDevice: 'NVIDIA RTX 2000 Ada Generation Laptop GPU/PCIe/SSE2'
Details: [1x1 struct]
>>
  댓글 수: 2
li
li 2024년 11월 7일
其实大体思路就是首先确保openGL能够检测到你的独立显卡,然后再在matlab中启用硬件加速

댓글을 달려면 로그인하십시오.

답변 (5개)

Adam
Adam 2025년 1월 27일 20:08
Running Matlab 2024b on Ubuntu 22.04.5, I find that setting the environment variable JAVA_TOOL_OPTIONS to '-Djogl.disable.openglarbcontext=1' will also make this error go away. E.g.:
JAVA_TOOL_OPTIONS='-Djogl.disable.openglarbcontext=1' matlab
I think this is generally a better solution than creating a java.opts file as described above. In my hands, the java.opts file had to be in the current working directory when I launched Matlab. (Not just in the directory where the Matlab executable lives.) This is a problem b/c I generally want to launch Matlab from many different working directories, and I don't want to create a java.opts file in all of them.
Given the above, I simply added the line
export JAVA_TOOL_OPTIONS='-Djogl.disable.openglarbcontext=1'
to my .bashrc file to make the error go away. This works no matter what directory you are in when you launch Matlab.

Bilal
Bilal 2024년 11월 7일
편집: Bilal 2024년 11월 7일
Setting up an environment variable solved the issue and improved the graphics renderer (although softwareopengl fixes the error but produces poor graphics rendering)
In a terminal:
export DRI_PRIME=0
So run matlab in a terminal like:
export DRI_PRIME=0 && ./matlab -desktop &
I have two GPUs: DRI_PRIME=0 implements my iGPU, which is intel's integrated gpu, and DRI_PRIME=1 implements my NVIDIA GPU.
try both value and test it with this command in MATLAB Command Window:
rendererinfo
this is my output:
rendererinfo
ans =
struct with fields:
GraphicsRenderer: 'OpenGL Hardware'
Vendor: 'Intel'
Version: '4.6 (Compatibility Profile) Mesa 24.2.4-1~24.04-tux1'
RendererDevice: 'Mesa Intel(R) Graphics (RPL-S)'
Details: [1×1 struct]

Himanshu
Himanshu 2024년 10월 4일
Hello,
I see that you are trying to resolve a 3D accelerated OpenGL rendering issue with MATLAB R2024b on Ubuntu LTS 24.04, which didn't occur in MATLAB R2024a.
You can follow the below steps to resolve this issue:
1) Executing the following command in a Linux Shell to start MATLAB. This command instructs MATLAB to only use software OpenGL libraries.
$ matlab -softwareopengl
2) Create a file with the name 'java.opts' in the directory where MATLAB is executed, containing the line:
-Djogl.disable.openglarbcontext=1
Then start MATLAB and everything should work as expected.
Please refer to the below documentation for more information.
Start MATLAB program from Linux system prompt: https://www.mathworks.com/help/matlab/ref/matlablinux.html
I hope this helps.
  댓글 수: 2
Jani
Jani 2024년 10월 14일
This looks like a AI generated answer. The problem/bug is that 3D accerelation does not work and the flag -softwaregl just disables 3D acceleration, so that Matlab starts.
Yoav
Yoav 2024년 10월 15일
편집: Yoav 2024년 10월 15일
The 2nd step is a copy of this (Willi Mutschler's) answer, although a bit clearer IMO. When using the linked solution I missed the '-' at the beggining of the fix and it didn't work for me.
Is it possible to amend the old one to be a bit clearer and just link it?

댓글을 달려면 로그인하십시오.


li
li 2024년 11월 7일
편집: Walter Roberson 2025년 2월 2일 11:36
我似乎找到了这个问题的解决方法,首先使用这个链接中的方法
然后再使用这个链接中的方法即可
其实大体思路就是首先确保openGL能够检测到你的独立显卡,然后再在matlab中启用硬件加速,经过我的测试可以解决这个问题

Tobias
Tobias 2025년 2월 2일 11:04
Luckily i found this:
It's says that you have to set GTK_PATH to the path or your gtk modules.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by