robot_dart icon indicating copy to clipboard operation
robot_dart copied to clipboard

Segfault on MacOS when shadows are on (GRAPHIC ON)

Open c-joly opened this issue 1 year ago • 3 comments

Hi @costashatz, here is in issue linked to the review https://github.com/openjournals/joss-reviews/issues/6771

Launching the examples in graphical mode on MacOS 14.5 (ARM64) results in a segfault due to OpenGL immediately (C++) and after about one second (Python bindings). Deactivating the shadows solve the problem (tested by updating some examples in Python and C++).

I saw there is already a warning message mentioning unexpected behavior with shadows on MacOS. In turns out that with my configuration, there is no behavior at all (☠️).

Do you think you can patch the examples to switch off the shadows by default, or better to deactivate them if the Darwin architecture (==MacOS) is detected? In Python, the test can be made easily thanks to the function system of the module platform.

c-joly avatar Jun 28 '24 10:06 c-joly

@c-joly thank you for your hard work. I will try to reply to all of your issues.

Deactivating the shadows solve the problem

Nice to hear!

better to deactivate them if the Darwin architecture (==MacOS) is detected?

Yes. This is what I will do. I am already checking for Darwin architecture in my code. So this should be easy. It was just that shadows were working in some machines, and producing some small artifacts on others. But on yours, it seems that they do not work at all.

It's unclear to me why, but the easiest workaround is to indeed disable shadows by default on Mac.

Thanks again!

costashatz avatar Jun 28 '24 11:06 costashatz

It's unclear to me why, but the easiest workaround is to indeed disable shadows by default on Mac.

I found on some forum that there is no support anymore of OpenGL on MacOS. Some people mention that the bugs and compatibility issues may be worse in the future. It looks like Apple would like to force developers to use Metal on MacOS, which is now the only graphics API officially supported.

c-joly avatar Jun 28 '24 14:06 c-joly

Hi @costashatz, a little update about these segfault. I figured out they happen only when my computer is docked and an extra screen is connected. I figured out by accident that I can run the examples in shadowed mode when I used my laptop without any extra screen... 🫤

c-joly avatar Jul 04 '24 13:07 c-joly

@c-joly I managed to replicate this issue. I was able to get the crash also by moving the window extensively around the screen (even when connected to one screen).

The examples run but they can very easily crash. This issue because of 2 reasons:

  1. Mac OSX does not support OpenGL, only a subpart of it. For this reason, my shaders for shadows compile but with important warnings (the number of lights variable gets a random value!). This can obviously result in accessing memory that does not exist or getting junk values that make the process crash.

  2. The HiDPI scaling works differently on Mac and Linux. I have spent most of my time (when writing the graphics) optimizing for the Linux case, and thus it is possible that on Mac we access memory that is not defined.

My intuition tells me that (2) is what causes the issue. This is also "validated" by the fact that everything runs fine in Windowless mode where HiDPI is not there (there is no window scaling when there's no window! hahah).

I will disable shadows by default in Mac windowed cases so that the user experience is better, add some comments about this behavior in the docs, and create a github issue so that I remember to try and fix this at some point.

I will ping you once I have completed all of the above.

costashatz avatar Aug 29 '24 10:08 costashatz

This should be fixed by https://github.com/NOSALRO/robot_dart/commit/9412aa2936e6f331431708d2c4d04ee8af635463 (and see https://github.com/NOSALRO/robot_dart/issues/223). @c-joly let me know if I forgot something.

costashatz avatar Sep 25 '24 06:09 costashatz