Hello, for some reason the code I am trying to write throws an exception about using a priviledged instruction. Problem is it is just comparing two values and throwing this out there at me. Maybe I am completely missing something.
Oh and I know its pretty ugly code, you don't need to tell me ^_^

for(int run = 1; run <= 4; run++)
{
	FILE* temp;

	char* tempin;


	switch(run)
	{
	case 1:
		tempout = "temp1";
		tempin = file_name_in;
		break;
	case 2:
		tempout = "temp2";
		tempin = "temp1";
		break;
	case 3:
		tempout = "temp3";
		tempin = "temp2";
		break;
	case 4:
		tempout = "temp4";
		tempin = "temp3";
		break;
	}

	ifstream infile (tempin);

	temp = fopen(tempout, "w");

	double max_x = -9999999;
	double max_y = -9999999;
	double min_x = 9999999;
	double min_y = 9999999;

	int swathnum = 1;

	vector<Lidar> Swath;

	Lidar * pLidar;

	double numberholder;

	if(run == 2 || run == 4)
		while (!infile.eof())
		{
			pLidar = new Lidar;	

			infile >> numberholder;	
			double lastone = numberholder;
			pLidar->SetX(numberholder);

			infile >> numberholder;
			pLidar->SetY(numberholder);
		
			infile >> numberholder;
			pLidar->SetZ(numberholder);

			infile >> numberholder;
			pLidar->SetGround1(numberholder);

			if(run == 4)
			{
				infile >> numberholder;
				pLidar->SetGround2(numberholder);

				infile >> numberholder;
				pLidar->SetGround3(numberholder);
			}

			if(min_x > pLidar->GetX())
				min_x = pLidar->GetX();


			delete pLidar;

			if(lastone-min_x >= 5)
				break;

		}

	while (!infile.eof())
	{
		infile >> numberholder;
		
		if(infile.eof())
			break;	
		pLidar = new Lidar;
		pLidar->SetX(numberholder);

		infile >> numberholder;
		pLidar->SetY(numberholder);
		
		infile >> numberholder;
		pLidar->SetZ(numberholder);

		if(run >=2)
		{
			infile >> numberholder;
			pLidar->SetGround1(numberholder);
		}

		if(run >=3)
		{
			infile >> numberholder;
			pLidar->SetGround2(numberholder);
		}

		if(run >=4)
		{
			infile >> numberholder;
			pLidar->SetGround3(numberholder);
		}

		if(min_x > pLidar->GetX())
		{
			min_x = pLidar->GetX();
		}
		if(min_y > pLidar->GetY())
		{
			min_y = pLidar->GetY();
		}
		if(max_x < pLidar->GetX())
		{
			max_x = pLidar->GetX();
		}
		if(max_y < pLidar->GetY())
		{
			max_y = pLidar->GetY();
		}
					
		Swath.push_back(*pLidar);
		delete pLidar;

		double cell_y = min_y + cellsize;

		if((Swath.back().GetX() - min_x) >= cellsize)
			findpoints(Swath, temp, max_x, max_y, min_x, min_y, cell_y, tolerance, cellsize, separator_sign, date, swathnum, run);
	}


	infile.close();
	fclose(temp);


}

The exception gets thrown at if(min_x > pLidar->GetX()) Any help would be great, and any other questions you have throw them at me, thanks!

Cameron

Recommended Answers

All 6 Replies

Could this be the ol' Why it's bad to use feof() to control a loop thing, I wonder?

I checked that out and change my loops accordingly. At least I think they are, correct me if I am wrong. Another helpful bit of information. When it throws this exception it opens up the file ostream and gives me a specific line from that file, namely basic_ostream<char, _Traits>& operator<<( Thank you very much though for the suggestion.

for(int run = 1; run <= 4; run++)
{
	FILE* temp;

	char* tempin;


	switch(run)
	{
	case 1:
		tempout = "temp1";
		tempin = file_name_in;
		break;
	case 2:
		tempout = "temp2";
		tempin = "temp1";
		break;
	case 3:
		tempout = "temp3";
		tempin = "temp2";
		break;
	case 4:
		tempout = "temp4";
		tempin = "temp3";
		break;
	}

	ifstream infile (tempin);

	temp = fopen(tempout, "w");

	double max_x = -9999999;
	double max_y = -9999999;
	double min_x = 9999999;
	double min_y = 9999999;

	int swathnum = 1;

	vector<Lidar> Swath;

	Lidar * pLidar;

	if(run == 2 || run == 4)
		while (infile >> numberholder, infile.eof() != 1)
		{
			pLidar = new Lidar;

			infile >> numberholder;
			double lastone = numberholder;
			pLidar->SetX(numberholder);

			infile >> numberholder;
			pLidar->SetY(numberholder);

			infile >> numberholder;
			pLidar->SetZ(numberholder);

			infile >> numberholder;
			pLidar->SetGround1(numberholder);

			if(run == 4)
			{
				infile >> numberholder;
				pLidar->SetGround2(numberholder);

				infile >> numberholder;
				pLidar->SetGround3(numberholder);
			}

			if(min_x > pLidar->GetX())
				min_x = pLidar->GetX();


			delete pLidar;

			if(lastone-min_x >= 5)
				break;

		}

	while (infile >> numberholder, infile.eof() != 1)
	{

		pLidar = new Lidar;
		pLidar->SetX(numberholder);

		infile >> numberholder;
		pLidar->SetY(numberholder);
		
		infile >> numberholder;
		pLidar->SetZ(numberholder);

		if(run >=2)
		{
			infile >> numberholder;
			pLidar->SetGround1(numberholder);
		}

		if(run >=3)
		{
			infile >> numberholder;
			pLidar->SetGround2(numberholder);
		}

		if(run >=4)
		{
			infile >> numberholder;
			pLidar->SetGround3(numberholder);
		}

		if(min_x > pLidar->GetX())
		{
			min_x = pLidar->GetX();
		}
		if(min_y > pLidar->GetY())
		{
			min_y = pLidar->GetY();
		}
		if(max_x < pLidar->GetX())
		{
			max_x = pLidar->GetX();
		}
		if(max_y < pLidar->GetY())
		{
			max_y = pLidar->GetY();
		}

		Swath.push_back(*pLidar);
		delete pLidar;

		double cell_y = min_y + cellsize;

		if((Swath.back().GetX() - min_x) >= cellsize)
			findpoints(Swath, temp, max_x, max_y, min_x, min_y, cell_y, tolerance, cellsize, separator_sign, date, swathnum, run);
	}


	infile.close();
	fclose(temp);


}

Is there some sort of output statement in findpoints ?

[aside]Rather than

while (infile >> numberholder, infile.eof() != 1)

Why not just this?

while (infile >> numberholder)

Is there some sort of output statement in findpoints ?

[aside]Rather than

while (infile >> numberholder, infile.eof() != 1)

Why not just this?

while (infile >> numberholder)

I did not realize that would work with c++, thank you very much. and yes, findpoints does some output work.

void findpoints(vector<Lidar> &Swath, FILE* temp, double &max_x, double &max_y, double &min_x,double &min_y, double cell_y, double tolerance, double cellsize, char separator_sign, time_t &date, int &swathnum, int run)
{
	double min_z = 99999999;
	char printstring[256];
	vector<Lidar> FinalCell;
	if(run == 3 || run == 4)
		cell_y += 5;
			
	for(; cell_y <= max_y; cell_y += cellsize)
	{
		bool found = false;
		for(int unsigned a = 0; a < Swath.size(); a++)
			if((Swath[a].GetY() - cell_y) <= cellsize && Swath[a].GetY() >= cell_y)
			{
				FinalCell.push_back(Swath[a]);
				found = true;
				if(min_z > Swath[a].GetZ())
					min_z = Swath[a].GetZ();
			}
		if(found)
			for(int unsigned b = 0; b < FinalCell.size(); b++)
			{
					lidardouble2string(printstring, FinalCell[b].GetX()); fprintf(temp, printstring);
					fprintf(temp, "%c", separator_sign);

					lidardouble2string(printstring, FinalCell[b].GetY()); fprintf(temp, printstring);
					fprintf(temp, "%c", separator_sign);

					lidardouble2string(printstring, FinalCell[b].GetZ()); fprintf(temp, printstring);
					char holder [33];
					if(run == 1)
						if(FinalCell[b].GetZ() <= min_z + tolerance)
							FinalCell[b].SetGround1(1);
						else
							FinalCell[b].SetGround1(0);
					if(run >=1)
					{
						fprintf(temp, "%c", separator_sign);

						itoa(FinalCell[b].GetGround1(), holder, 10);
						fprintf(temp, holder);
					}
					if(run == 2)
						if(FinalCell[b].GetZ() <= min_z + tolerance)
							FinalCell[b].SetGround2(1);
						else
							FinalCell[b].SetGround2(0);
					if(run >=2)
					{
						fprintf(temp, "%c", separator_sign);
						itoa(FinalCell[b].GetGround2(), holder, 10);
						fprintf(temp, holder);
					}
					if(run == 3)
						if(FinalCell[b].GetZ() <= min_z + tolerance)
							FinalCell[b].SetGround3(1);
						else
							FinalCell[b].SetGround3(0);
					if(run >=3)
					{
						fprintf(temp, "%c", separator_sign);
						itoa(FinalCell[b].GetGround3(), holder, 10);
						fprintf(temp, holder);
					}
					if(run == 4)
						if(FinalCell[b].GetZ() <= min_z + tolerance)
							FinalCell[b].SetGround4(1);
						else
							FinalCell[b].SetGround4(0);
					if(run >=4)
					{
						fprintf(temp, "%c", separator_sign);
						itoa(FinalCell[b].GetGround4(), holder, 10);
						fprintf(temp, holder);
					}


					fprintf(temp, "\012");

				}

		FinalCell.clear();

		min_z = 99999999;

	}

	Swath.clear();

	max_x = -9999999;
	max_y = -9999999;
	min_x = 9999999;
	min_y = 9999999;

	time(&date);

	cout << "Done with swath number " << swathnum << endl;
	swathnum++;
	cout << "End Time: " << ctime(&date) << endl;

}

Thank you again!

Sorry about double posting, but any other ideas about what this could be would be amazing. Thank you.

Cameron

Ok, I believe I have solved this now and am going to explain to the rest of the world what fixed it.

The main problem was in my object declaration. For some reason, because I was using stack instead of pointers it got angry when I tried to access them, therefore throwing that exception.

Thanks for all your help everyone.

Cameron

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.