Program stops working when loading new map

Started by
3 comments, last by PuReInSaNe 11 years, 3 months ago

At first you can select a file using GetOpenFileName.
This is saved in a string and then send to this function below.
Sometimes, when loading a map which is in another directory, the program crashes and I get "the program stopped working".
Now, if I add w_engine->message(layer1) after I got the content of layer1 using Gettext() via tinyxml, the program won't crash. (see comments inside code)
Still, thats an ugly way on how to do it. Do you guys happen to know why the error pops up and how to fix it?t


void Map::loadnew(std::string filename)
	{
	const char* layer1 = "";
	char* text = "";
	char * pch = "";
	w_engine->message("Lade Map: "+filename);
	int h = mapd.LoadFile( filename.c_str() );  
	layer1 = mapd.FirstChildElement("map")->FirstChildElement("layer")->GetText();
	x = mapd.FirstChildElement("map")->IntAttribute("x");
	y = mapd.FirstChildElement("map")->IntAttribute("y");
	name = mapd.FirstChildElement("map")->Attribute("name");
        //w_engine->message(layer1); if I add this here it would fix it.
	text = new char[strlen(layer1)];
    strncpy(text, layer1, strlen(layer1));
	pch = strtok (text,",;");
	tilemap = new int*[y];
	animmap = new int*[y];
	for(int i = 0; i < y; i++){
		tilemap[i] = new int[x];
		animmap[i] = new int[x]; }

	int w_x = 0;
	int w_y = 0;
	int k = 0;
	//BUG happens here as far as I know
	while (pch != NULL)
	{
		if(w_x == x)
		{
			w_x = 0;
			w_y++;
		}
		if(k == 0)
		{
		tilemap[w_y][w_x] = atoi(pch);
		k = 1;
		}
		else if(k == 1)
		{
		animmap[w_y][w_x] = atoi(pch);
		k = 0;
		w_x++;
		}
		pch = strtok(NULL, ",;");
	}
	delete text;
	}

One xml file


<map x="50" y="50" name="Test">
    <layer id="0">0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0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,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0</layer>
</map>

Advertisement

Well, your code has almost zero error checking, so the first step would be to rectify that. If that doesn't pinpoint the problem, try to reproduce the problem in a debugger.

I can see one obvious bug: you are calling "delete" on a pointer allocated with "new[]". You need to use "delete []", or better still switch to std::string or std::vector.

strlen doesn't include the null-terminator; when allocating space for a string using strlen, you must include an additional character for the null-terminator. (Why are you using both std::string and c-style strings?)
Here's another bad habbit to get out of; Don't do this in C++:

	const char* layer1 = "";
	char* text = "";
	char * pch = "";
...
  	layer1 = mapd.FirstChildElement("map")->FirstChildElement("layer")->GetText();
...
	text = new char[strlen(layer1)];
...
	pch = strtok (text,",;");
Instead, declare your variables at first use:

  	const char *layer1 = mapd.FirstChildElement("map")->FirstChildElement("layer")->GetText();
...
	char *text = text = new char[strlen(layer1)+1]; // Should really be a vector os string here
...
	char *pch = strtok(text,",;");
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

just as fastcall22 said, the null-terminator was not included. Fixed it by adding this:


string layer1 = mapd.FirstChildElement("map")->FirstChildElement("layer")->GetText();


char* text = new char[layer1.size()+1];
strcpy(text, layer1.c_str());
char* pch = strtok(text,",;");

This topic is closed to new replies.

Advertisement