0

I am working with a custom game engine, and in the engine's Object class:

std::string gObject::exepath;
gObject::gObject() {
    char temp[256];
    exepath = getcwd(temp, sizeof(temp));
    exepath += "/";
    for (int i = 0; i < exepath.size(); i++) {
        if (exepath[i] == '\\') {
            exepath[i] = '/';
        }
    }
}

This is how the engine gets the exepath. It also has a images path coded in:

std::string gObject::gGetImagesDir() {
    if (releasescaling == 1) return exepath + "assets/mipmaps/" + resolutiondirs[releaseresolution];
    return exepath + "assets/images/";
}

This path works in eclipse and returns: ../GlistApp/assets/images/, but when i tried to move the engine into VS Code, it returns the path: ../GlistApp/build/assets/images/. Which is actually the expected behaviour since the app is being run in that folder.

Any explanation on why this works in eclipse but not on VS Code? Also the engine is open-source, so how would I go about changing and correcting this issue for VS Code?

  • so is your actual question how to change the working directory when launching a program in visual studio code? How does this relate to cmake? – Alan Birtles Jul 01 '21 at 09:42
  • Removed the cmake tag, I was just using the cmake to build, it was not related to subject. And yes my question is how do i make the exepath not point to the build path and instead to the GlistApp directory. – guacamoleku Jul 01 '21 at 09:43
  • I know that in VS Code python has something like `python.dataScience.notebookFileRoot` option to modify getcwd. Just wondering if I can achieve something like this. – guacamoleku Jul 01 '21 at 09:48
  • What doesn't work on VS Code? It looks like everything works as expected and as coded. The build directory can be changed in VS Code config. But that's not a C++ question. – Evg Jul 01 '21 at 09:52
  • Yeah as I said, everything works as expected. But in eclipse, not so much. As it returns the top directory for the app as opposed to VS Code returning the actual execution path. And my question is, "Why". Why does it return the exepath as top directory in eclipse. – guacamoleku Jul 01 '21 at 09:56
  • 1
    the location of the executable has no relation to the working directory. It's entirely controlled by whatever is launching your process. If you want to get the path to the executable see https://stackoverflow.com/questions/1528298/get-path-of-executable. Eclipse and VS Code simply have different default working directories. How to change them in VS Code depends on how you are launching your exe – Alan Birtles Jul 01 '21 at 10:03
  • @AlanBirtles Can you explain a bit more? How exactly would I go about changing the working directory in VS Code? I am currently using CMake to build and run, does that affect anything? – guacamoleku Jul 01 '21 at 10:14
  • 2
    What are you actually running in your VSCode build script? You can set '"cwd": "path/to/somewhere"' – Ryan Pepper Jul 01 '21 at 10:37
  • 1
    see the documentation https://github.com/microsoft/vscode-cmake-tools/blob/develop/docs/debug-launch.md – Alan Birtles Jul 01 '21 at 11:02

0 Answers0