Game Development Community

bizarre crashing bug when assigning to StringTableEntry from data structure

by Thomas -elfprince13- Dickerson · in Torque 3D Professional · 09/01/2011 (9:50 am) · 2 replies


LDFileData * bufferFile(LDFileSearchInfo &fileSearchInfo){
		
		LDFileData * ret;
		U32 cacheDepth = gLDrawPrintCacheTree ? 0 : -1;
		
		//Something is going desperately wrong here!
		//Overwriting a chunk of the heap or some bad stuff like that
		AssertFatal(fileSearchInfo.path != NULL && fileSearchInfo.name != NULL && !fileSearchInfo.subFile, "LDFileSearchInfo passed to LDParse::bufferFile() was for a sub-file, or was the result of a failed search");
		StringTableEntry filename;
		filename = NULL;

		//
		// Stepping over this line causes the program to crash.
		// path = 0x08673088 "C:/Program Files (x86)/LDraw/PARTS/2531.dat"
		//
		filename = fileSearchInfo.path;
		
		FileStream *s = new FileStream;
		char* script = NULL;
		if( !s->open (filename, Torque::FS::File::Read) ) {
				// ...

About the author

Computer Science, Mathematics, and Physics major at Saint Michael's College. Project lead for FreeBuild. Administrator, Cemetech tech community. Webmaster for the Village2Village Projects and the Vermont Sustainable Heating Initiative.


#1
09/01/2011 (9:53 am)
Quote:HEAP[FreeBuild_DEBUG.exe]: Heap block at 09219318 modified at 092193C4 past requested size of a4
Windows has triggered a breakpoint in FreeBuild_DEBUG.exe.

This may be due to a corruption of the heap, which indicates a bug in FreeBuild_DEBUG.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while FreeBuild_DEBUG.exe has focus.

The output window may have more diagnostic information.

[edit]

changing the problematic assignation to this:
//Overwriting a chunk of the heap or some bad stuff like that
		AssertFatal(fileSearchInfo.path != NULL && fileSearchInfo.name != NULL && !fileSearchInfo.subFile, "LDFileSearchInfo passed to LDParse::bufferFile() was for a sub-file, or was the result of a failed search");
		StringTableEntry filename;
		filename = NULL;
		filename = "toothpaste";
		filename = StringTable->insert("C:/Program Files (x86)/LDraw/PARTS/2531.dat");
		//  
		// Stepping over this line causes the program to crash.  
		// fileSearchInfo.path == filename already, after the last step, but the assignment crashes it.
        // 
		filename = fileSearchInfo.path;
Still causes the crash in the same place, namely when I try to assign the string from fileSearchInfo.path, but the debugger tells me it has the same contents as the string I assign immediately before that.

[edit #2]
Here is the code that instantiates fileSearchInfo:
LDFileSearchInfo * findLDrawFile(const char * filename, Vector<LDFileData*> &subfile_search_stack)
	{
		
		U32 i;
		U32 cacheDepth = gLDrawPrintCacheTree ? 0 : -1;
		StringTableEntry file = StringTable->insert(filename);
		
		LDCacheNode * cacheRoot = LDCacheNode::getRoot();
		LDCacheNode * subFileList = NULL;		
		LDCacheNode * cachedFile = NULL;
		LDFileSearchInfo * ret = new LDFileSearchInfo;
		ret->name = NULL;
		ret->path = NULL;
		ret->subFile = false;
		ret->file = NULL;
		
		U32 ldis = gLDrawInstallation.size();
		if(ldis % 3) {
			Con::errorf("findLDrawFile called before any entries in $pref::LDraw::Directory were validated. Please call checkLDrawDirectory()");
			
		} else if(!subfile_search_stack.empty()) for(i = 0; i < subfile_search_stack.size(); i++){
			subFileList = subfile_search_stack[i]->getSubfileCache();
			if((subFileList != NULL) && // Did we get passed some sub-files?
			   ((cachedFile = subFileList->find(file,cacheDepth)) != NULL) && // Is the file name among the sub-files?
			   (cachedFile->getContents() != NULL) // Is it really holding something?
			   ) {
				ret->name = file;
				ret->path = cachedFile->getContents()->getPath();
				ret->subFile = true;
				ret->file = cachedFile->getContents();
				break;
			}
		} 
		
		if(ret->name == NULL){
			if((cacheRoot != NULL) &&
			   ((cachedFile = cacheRoot->find(file,cacheDepth)) != NULL) && // Is the file name among the sub-files?
			   (cachedFile->getContents() != NULL) && // Is it really holding something?
			   (cachedFile->getContents()->hasCache() || cachedFile->getContents()->hasSubfiles()) // Have we cached it yet?
			   ) {
				ret->name = file;
				ret->path = cachedFile->getContents()->getPath();
				ret->file = cachedFile->getContents();
			} else {
				
				//Assumes a beginning->end traversal to ensure proper precedence.
				
				StringTableEntry path;
				char pReturn[1024];
				
				for(std::deque<std::string>::const_iterator itr = gLDrawInstallation.begin(); 
					itr!=gLDrawInstallation.end(); 
					++itr
					) {
					path = StringTable->insert(itr->c_str());
					Platform::makeFullPathName(file, pReturn, 1024, path);
					if(Platform::isFile(pReturn) && !Platform::isDirectory(pReturn)){
						ret->name = file;
						ret->path = StringTable->insert(pReturn);
						break;
					}
				}
				
				
			}
		}
		
		
		if(ret->name == NULL) Con::warnf("File '%s' not found in LDraw directories",file);
		return ret;
	}
#2
09/01/2011 (11:46 am)
Nevermind, the debugger was lying to me. The stack trace after the crash would jump to an entirely different portion of code then the one I was stepping through when the crash occurred. I think I have it figured out.