Game Development Community

Can't open file

by Richard_H · in Torque Game Engine · 05/27/2007 (7:23 am) · 3 replies

Hi,
I've been working on my Random Mission Pack and have come across a frusturating problem, whenever I attempt to randomly generate a mission 22 x 22 pieces somewhere near the middle it begins being unable to open the mission file to write more data. I've traced this problem to a failing of
stream.open (fileName, (FileStream::AccessMode) accessMode)
in
bool ResManager::openFileForWrite (FileStream & stream, const char *fileName, U32 accessMode)
{
   if (!isValidWriteFileName (fileName))
   {
	  Con::warnf("Filename '%s' is not valid.", fileName);
      return false;
   }

   // tag it on to the first directory
   char path[1024];
   dStrcpy (path, fileName);
   char *file = dStrrchr (path, '/');
   if (!file)
   {
      Con::warnf("Filename '%s' cannot be saved in root.", fileName);
      return false;      // don't allow storing files in root
   }
   *file++ = 0;

   if (!Platform::createPath (fileName))   // create directory tree
   {
      Con::warnf("Could not create a path for filename '%s'.", fileName);
      return false;
   }
   if (!stream.open (fileName, (FileStream::AccessMode) accessMode))
   {
      Con::warnf("Could not open a stream for filename '%s'.", fileName);
      return false;
   }

   // create a resource for the file.
   ResourceObject *ro = createResource (StringTable->insert (path), StringTable->insert (file));
   ro->flags = ResourceObject::File;
   ro->fileOffset = 0;
   ro->fileSize = 0;
   ro->compressedFileSize = 0;
   return true;
}
When I try to run the debug version XCode (yes, I'm on a mac) displays these pics.
http://img242.imageshack.us/img242/7136/picture1th0.png
http://img169.imageshack.us/img169/9471/picture2ko1.png
It also says
Quote: Program received signal: "EXC_BAD_ACCESS"

Can anyone help me? If you do I'll send you a free coy of my Random Mission Pack.

#1
05/27/2007 (6:29 pm)
Are you sure you haven't already opened the stream somewhere?
#2
05/27/2007 (8:17 pm)
Have you added the file that you created to your Resource Manager ?

Aun.

Torque-Motion
#3
05/28/2007 (1:14 pm)
I have traced the problem to fopen failing, I'm not sure why this is, but I realized calling %file.writeLine for each line of my (rather large) missions was rather wasteful, so I am now trying to store the entire mission file in an character array, then write the string into the file. Thus, limiting to the file being opened once, now I'm wondering if it's possible to make a char array with unlimited length. (The missions will be rather varied.)