iMac logging out whenever seemingly stressful programs are launched Recently my mac has been mysteriously logging itself out whenever I attempt to launch any resource-intensive programs, such as games (roblox) and 3D applications. I have looked at many solutions to similar problems online, such as resetting PRAM and NVRAM, and have even gone so far as to reinstall MacOS. Yet the problem persists. 
When I open said applications, they work for about 2-3 minutes and then suddenly freeze before the screen goes black and a small loading icon appears and then it takes me to the login screen.

Does anyone have any idea what could be going on?

Whenever it crashes, files such as this pop up in /Library/Logs/DiagnosticsReports

Kernel_2019-10-29-124911_Username-iMac-7.gpuRestart


And the content: 



That's what I get when it crashes with blender, but I'm also getting some WindowServer logs too.
The cause for your issue is most likely related to the graphics processing unit (GPU) of your iMac. This is what's commonly referred to as a graphics card.

Some games and applications will place the GPU under a much heavier load compared to others. 

For example, using a word processor will not tax the GPU much at all, but using applications such as Photoshop, Maya, Render, Final Cut Pro, Motion, etc will place a much heavier burden on the GPU. I'm not familiar with Roblox, but it's likely that it's also taxing the GPU heavily.

Normally this would not be a problem, but if your Mac has a GPU that has developed a problem, it'll be enough to effectively cause it to crash in such a way that your Mac has to reboot. In this scenario it's a hardware fault that may mean repairing or replacing the GPU.

Some Mac models were more prone than others to these types of problems. For example, the 27" iMac model from mid-2011 was the subject of a graphics card replacement program for exactly this type of issue.

However, it doesn't necessarily have to be a hardware fault. Software can often cause problems. For example, it could be a conflict between software, drivers, etc or a lack of graphics memory (especially if running multiple apps simultaneously). You could try troubleshooting this further by only running one application and seeing what happens. Perhaps testing in Safe Mode may be an option as well.



Remove any CUDA and NVIDIA drivers

Since you're running macOS Mojave (or above), you should be aware that any CUDA and NVIDIA drivers you have installed aren't supported.

To remove these:


Launch Terminal (found within your Utilities folder)
Copy and paste the following commands, one by one, into Terminal followed by pressing enter on your keyboard. Each time you do this you'll also have to enter your Admin password.


sudo rm -rf /Library/Extensions/CUDA.kext
sudo rm -rf /Library/Frameworks/CUDA.framework 
sudo rm -rf /Library/LaunchAgents/com.nvidia.CUDASoftwareUpdate.plist 
sudo rm -rf /System/Library/StartupItems/CUDA 
sudo rm -rf /usr/local/cuda

Go to Apple > System Preferences
Right-click on the CUDA preference pane
Select the Remove "CUDA" preference pane option


OPTIONAL: If you also have NVIDIA Web Drivers installed (that's a 'yes' if you have the NVIDIA icon in the menu bar), then follow these additional steps:


Still in System Preferences, click the NVIDIA Driver Manager preference pane
Select the Graphics Drivers tab
Click on the padlock and type your password
Click the Open Uninstaller button
Click Uninstall 
Complete the Uninstall process and restart your iMac