mathworks / MATLAB-extension-for-vscode

This extension provides support for editing MATLAB® code in Visual Studio® Code and includes features such as syntax highlighting, code analysis, navigation support, and more.
https://marketplace.visualstudio.com/items?itemName=MathWorks.language-matlab
MIT License
215 stars 13 forks source link

Linux Intel graphics software OpenGL error #140

Closed JakeSkelton closed 2 months ago

JakeSkelton commented 2 months ago

When I first started using MATLAB on Linux, I ran into an issue where the software would default to using software OpenGL for rendering. I fixed this following the forum post here by modifying java.opts in the MATLAB binary directory. This fix works in the MATLAB IDE: running 'opengl info' yields '... HardwareSupportLevel: 'full' ...'.

Using the VSCode MATLAB extension, however, any plotting throws warnings that software OpenGL is being used. And running 'opengl info' in the VSCode MATLAB terminal yields '... Software: 'true' \ HardwareSupportLevel: 'none (known graphics driver issues) ...'.

My setting for the MATLAB install path in VSCode is identical to that returned by 'matlabroot' in the MATLAB IDE terminal, so it looks as though java.opts is ignored by the MATLAB instance started by the VSCode extension.

If there is a better fix for hardware OpenGL support than java.opts I am happy to do that too.

My system: Operating System: Ubuntu 22.04.4 Kernel: Linux 6.5.0-28-generic VGA compatible controller: Intel Corporation Device 46a8 (rev 0c) Kernel driver in use: i915 MATLAB: R2023a VSCode Extension: 1.2.1

dklilley commented 2 months ago

Hi @JakeSkelton, thanks for reporting this!

Can you try launching MATLAB from the system terminal using the -nodesktop startup flag, and then run the opengl info command again? Do you see the same output in that situation?

JakeSkelton commented 2 months ago

Thanks for the quick reply @dklilley

Running as you suggest, I get the 'right' output: ... Software: 'false' \ HardwareSupportLevel: 'full' ...

dklilley commented 2 months ago

Thank you for trying that out!

I have created an internal bug report for this with our graphics team. At the moment, this seems likely to be a bug with MATLAB. Because of that, I am going to close this issue for now. However, if we determine that a fix or workaround can be implemented in the extension, or if we have any additional questions, I will reopen this issue.

JakeSkelton commented 1 month ago

I'm just adding some more context that I missed when originally posting this issue. I had forgotten that to fix a similar OpenGL graphics issue on my system, while plotting with Python, I added the following environment variable to my bashrc export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 If I comment this out and reboot my system, then run the MATLAB binary, I get the errors mentioned above and MATLAB defaults to software rendering, so having this environment variable as well as a modified java.opts file both seem crucial to working OpenGL hardware rendering on my system.

I guess the conclusion here is that my system has some problems with OpenGL and the paths of the correct C++ binaries, which, if I recall, are to do with Conda pointing to different binaries. I think my experience above is therefore of limited relevance to the rest of the MATLAB community.

Hopefully this saves others time in going down rabbit holes trying to fix MATLAB rendering issues.

JakeSkelton commented 1 month ago

After some more digging this morning, the issue I was experiencing is not specific to the MATLAB VSCode extension, but rather an example of software referencing a prepackaged version of libstdc++.so rather than the system file. This seems to be an issue common to MATLAB, Conda installs of Python, and probably lots of other software.

I had added a fix to my bashrc earlier, loading the environment variable LD_PRELOAD, but this did not apply to the command issued to launch MATLAB by VSCode.

The fix that ended up working was suggested here by a MathWorks employee. The solution is just to rename the libstdc++.so instance in {matlabroot}/sys/os/glnxa64.

I hope this helps anyone else coming across this problem.