Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualSix222

Posted 30 August 2013 - 09:42 AM

I'm having some problems with reading a binary file, I keep getting an unhandled exception in XUtility.h. It reads the first sections of the file fine, but when it goes out of scope it crashes?

 

Here's my code:

void ViewEnts() {
	system("CLS");
	cout << "Entity List" << endl;
	
	ifstream file("entities.entl", ios::in | ios::binary);
	if(file.is_open()) {
		EntityHeader head;
		file.read((char*)&head, sizeof(EntityHeader));
		
		for(int x = 0; x != head.num; x++) {
			EntityStructure ent;
			file.read((char*)&ent, sizeof(EntityStructure));

			cout << "Entity " << x << ") " << ent.className << endl;
			cout << "Renderable: " << ent.isRenderable << endl;
			cout << "Script Location: " << ent.scriptLocation << endl;
			system("PAUSE");
			
		} //CRASHES HERE 
	} else {
		cout << "FATAL ERROR OCCURED: COULD NOT OPEN FILE" << endl;
		system("PAUSE");
	}

	file.close();
	system("PAUSE");
}

Also if I make "EntityStructure ent;" a global variable it will read the whole file fine until I exit the program which it then will crash?


#1Six222

Posted 30 August 2013 - 09:41 AM

I'm having some problems with reading a binary file, I keep getting an unhandled exception in XUtility.h. It reads the first section fine, but when it goes out of scope it crashes?

 

Here's my code:

void ViewEnts() {
	system("CLS");
	cout << "Entity List" << endl;
	
	ifstream file("entities.entl", ios::in | ios::binary);
	if(file.is_open()) {
		EntityHeader head;
		file.read((char*)&head, sizeof(EntityHeader));
		
		for(int x = 0; x != head.num; x++) {
			EntityStructure ent;
			file.read((char*)&ent, sizeof(EntityStructure));

			cout << "Entity " << x << ") " << ent.className << endl;
			cout << "Renderable: " << ent.isRenderable << endl;
			cout << "Script Location: " << ent.scriptLocation << endl;
			system("PAUSE");
			
		} //CRASHES HERE 
	} else {
		cout << "FATAL ERROR OCCURED: COULD NOT OPEN FILE" << endl;
		system("PAUSE");
	}

	file.close();
	system("PAUSE");
}

Also if I make "EntityStructure ent;" a global variable it will read the whole file fine until I exit the program which it then will crash?


PARTNERS