C++ CIMG suddenly stopped opening display

  c++, cimg, x11

I have now been working on a c++ project for quite some time now. I have been opening the display with the same method every time, passing a set path into a CImg<unsigned char> and then passing that object into the CImgDisplay, quite standard, and it worked every time. Then, I started passing the path through command-line arguments, which also worked perfectly well. However, once I switched back to hardcoding the path in order to use the debugger in VS Code, the program started spitting out a very descriptive error:

Exception has occurred

After doing some digging around, I found a bit better of a description of the error:

[CImg] *** CImgDisplayException *** [instance(0,0,0,[untitled])] CImgDisplay::assign(): Failed to open X11 display.
libc++abi.dylib: terminating with uncaught exception of type cimg_library::CImgDisplayException: [instance(0,0,0,[untitled])] CImgDisplay::assign(): Failed to open X11 display.

When running the program from the command-line (compiles perfectly), the error is a Segmentation fault: 11.

I tried to look online for the same error, even not related to CIMG as this is an X11-related error, but couldn’t find anything. The error persisted when I commented out the whole main function instead of the two image and display declaration lines. The code is like follows:

#define cimg_use_png
#include "CImg.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace cimg_library;
using namespace std;

int main(/*int argc, char *argv[]*/) {
    //CImg<unsigned char> og_pic(argv[1]), first_anim(og_pic.width(),og_pic.height(),1,3,127);
    CImg<unsigned char> og_pic("/Users/glebsvarcer/Desktop/my-stupid-little-programs/maze_solver/test13.png");
    CImgDisplay disp(og_pic, "Test");

    return 0;

What could be causing this? I really can’t move on in the project without the debugger, and would be really grateful if anyone has a solution to this.

Source: Windows Questions C++