Jump to content


Program can't find file's passed to it


  • You cannot reply to this topic
7 replies to this topic

#1 Phlex

    Member

  • Members
  • PipPip
  • 53 posts

Posted 05 September 2009 - 02:16 AM

Hey, I've been using the ray trace tutorial here - http://www.codermind...snel-blobs.html - and when I tried to use the source, I encountered a problem.
The sample source code is set up to read information from a txt file, it seems to work fine, although, when I pass in the names of images for a skybox, it does not work, they are defined like this in the txt file



  Cubemap.Up = alpup.tga;
  Cubemap.Down = alpdown.tga;
  Cubemap.Right = alpright.tga;
  Cubemap.Left = alpleft.tga;
  Cubemap.Forward = alpforward.tga;
  Cubemap.Backward = alpback.tga;


These are then read as such in the application:


    myScene.cm.name[cubemap::up] = sceneFile.GetByNameAsString("Cubemap.Up", emptyString);
    myScene.cm.name[cubemap::down] = sceneFile.GetByNameAsString("Cubemap.Down", emptyString);
    myScene.cm.name[cubemap::right] = sceneFile.GetByNameAsString("Cubemap.Right", emptyString);
    myScene.cm.name[cubemap::left] = sceneFile.GetByNameAsString("Cubemap.Left", emptyString);
    myScene.cm.name[cubemap::forward] = sceneFile.GetByNameAsString("Cubemap.Forward", emptyString);
    myScene.cm.name[cubemap::backward] = sceneFile.GetByNameAsString("Cubemap.Backward", emptyString);



The function works fine, however, when it gets to this part of the code:


    currentfile.open(name[up].c_str(), ios_base::binary);
    if ((!currentfile)||(!dummyTGAHeader(currentfile, sizeX, sizeY)))
        return false;


it returns false, and I don't know why, the files are in the same directory as the executable, but still, currentfile is not opening the file as it returns false. Any ideas? Thanks.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 05 September 2009 - 06:26 AM

Make sure that the current directory when you run the project is really set to the same directory as the executable. If this is Visual Studio for instance, it will be executed from the project directory while the executable is usually in a Release or Debug subdirectory. Alternatively, try specifying full paths for the files.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Phlex

    Member

  • Members
  • PipPip
  • 53 posts

Posted 05 September 2009 - 08:45 AM

Hey, I'm running the program outside of the IDE in the debug folder, so I don't need to worry about that. I've tried adding the entire file path but still no luck. I've checked that the strings are correct using this:


cout << name[up].c_str() << endl;


and they all have the correct string names, so I don't see why ifstream.open() is failing.

#4 Wernaeh

    Senior Member

  • Members
  • PipPipPipPip
  • 368 posts

Posted 05 September 2009 - 01:09 PM

You sure it is really the open() call that fails, and not the dummyTGAHeader() one ?

Cheers,
- Wernaeh
Some call me mathematician, some just call me computer guy. Yet, I prefer the term professional weirdo :)

#5 Phlex

    Member

  • Members
  • PipPip
  • 53 posts

Posted 05 September 2009 - 09:18 PM

Yeah it is, I separated them into separate if statements, if dummyTGAHeader is called first it will obviously fail because it relies on currentfile. So anyway, I ran

if(!currentfile)

and it still failed.

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 06 September 2009 - 01:41 AM

Are you in *nix, or Windows? If *nix, do the filenames match in case?

If you write a minimal testbed app and try to open the file, does it work?
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 Phlex

    Member

  • Members
  • PipPip
  • 53 posts

Posted 06 September 2009 - 08:16 AM

I'm on windows. When I ran a minimal testbed app, it worked fine when I used a

const char*

rather than using

name[up].c_str()

So I tried doing this:

const char* up = name[up].c_str();

currentfile.open(up, ios_base::binary);

But it wasn't happy
Also as a side note, I had to put in full directory paths, and double slashes to avoid escape sequence errors.

#8 Phlex

    Member

  • Members
  • PipPip
  • 53 posts

Posted 06 September 2009 - 08:37 AM

Ok so I've fixed it, there were several problems that were coming up. The main one was that the process of reading in the strings representing the file paths skipped tabs, new lines and spaces, so without spaces, folders like Documents and Settings, were copied incorrectly.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users