Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading files error...

Status
Not open for further replies.

falled

Programmer
Nov 3, 2006
47
ES
I'm creating a mesh loader for 3D games and fails me just loading the file.

I don't know why, but if I load a file of 1kb it loads perfectly and if is about 60kbs or above fails.

My impression is that the program haven't time enough to load the file, and when is_open() is requested returns error

Any suggestion?



Code:
fstream myfile;
	myfile.open ("caixa.obj");
	if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      	  ...DoActions...
    }
    myfile.close();
  }

  else cout << "Unable to open file\n"; 

	system("PAUSE");
	return 0;
 
> if (myfile.is_open())
This happens once, and only depends on whether the file exists, not how big it is. If you're getting "Unable to open file", then use something like perror() or strerror() to find out why (is the file missing, do you have permissions etc etc).

> while (! myfile.eof() )
Read this
> ...DoActions...
Maybe you're just not allocating enough space for whatever you're reading. You get away with poor memory allocation for small files, but with larger files the damage becomes too severe and it all falls apart.

If it is memory corruption, then you also need to look at all your other use of memory as many memory mis-use problems have a "cause" and "effect" which are not in the same place.

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top