• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Invalid Block type

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Mozly  Members

Posted 01 March 2011 - 06:01 PM

So I added a new class to my program that has many pointers.

There is nothing wrong until the last line.
I debugged until the point
return 0;

at the end of my main function and I get this error

I dont know why it gives me this. Can someone help me solve it.
Thanks.

### #2nobodynews  Members

Posted 01 March 2011 - 06:50 PM

Someone else may be able to figure out what's wrong with this information but I can't. Could you maybe post the class declaration/definition?

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

### #3Mozly  Members

Posted 01 March 2011 - 07:42 PM


class Button

{

protected:

SDL_Rect buttons[3];

SDL_Surface* button_image[6];

// plugin button

SDL_Rect Plug_in_button;

SDL_Surface* Plug_in_image[2];

//plugin process

bool Plug_in_process;

SDL_Rect Plug_in_box;

SDL_Rect* Plug_in_variables;

SDL_Surface** variable;

std::string* varstr;

//to cancel the plugin

SDL_Rect cancel;

std::string cancelstr;

SDL_Surface* cancelsur;

//plugin part 2

bool Plug_in_2;

//std::stringstream inputnum;

StringInput inputstr;

//plugin partt3

bool Plug_in_3;

public:

Button();

~Button()

{

for(int q=0; q<6;q++)

{

SDL_FreeSurface(button_image[q]);

}

SDL_FreeSurface(cancelsur);

delete cancelsur;

delete varstr;

delete variable;

delete button_image;

delete Plug_in_variables;

}

std::vector<Digit*> handle_events(std::vector<Digit*> elEquation);

void handle_display();

bool return_plug_in_bool(){return Plug_in_process;}

bool return_plug_in_bool2(){return Plug_in_2;}

bool return_plug_in_bool3(){return Plug_in_3;}

void plug_in_false(){Plug_in_process=false;}

void plug_in_false2(){Plug_in_2 = false; inputstr.reset_input();}

void plug_in_false3(){Plug_in_3 = false;}

//handles the buttons for plgin

void handle_plug_in_display();

void handle_plug_in_buttons();

void handle_plug_in_display2();

void handle_plug_in_buttons2();

void Plug_into(int variable_number)

{

plug_in_false();

Plug_in_2 = true;

//use the first values to hold stuff

varstr[0] = varstr[variable_number];

varstr[0] += "=";

variable[0] = TTF_RenderText_Solid(font,varstr[0].c_str(),fontcolor);

Plug_in_variables[0].w = variable[0]->w;

//center the box

Plug_in_variables[0].x = Plug_in_box.x + (int)((Plug_in_box.w/2)-(Plug_in_variables[0].w/2));

}

void Plug_in_func(std::vector<Digit*> delEquation)

{

//we are now in the process of pluggin in

Plug_in_process = true;

//make some boxes with variables

Plug_in_variables = new SDL_Rect[numofvar];

//as many surfaces as variables

variable = new SDL_Surface*[numofvar];

int *color_positions = new int[numofvar];

//sets the number of strings to number of variables

varstr = new std::string[numofvar];

for(int q=0; q<numofvar; q++)

{

varstr[q] = "";

variable[q] = NULL;

color_positions[q]=0;

}

//compaes to see if we have enough strings

int var_comparator = 0;

//get all the variables

for(int q=0; q< delEquation.size(); q++)

{

if(delEquation.at(q)->returnid()==2) //if its a variable check if it has come up

{

int matches = 0;

for(int w=0; w<numofvar;w++)//check all the initialized strings to see if this one matches a prevoius one

{

if(varstr[w] == delEquation.at(q)->return_svalue())

matches++;

}

if(matches ==0)//if there are no matches it is a new var

{

varstr[var_comparator] = delEquation.at(q)->return_svalue();

color_positions[numofvar]=q;

var_comparator++;

}

}

if(var_comparator == numofvar)//if you have enough variables then break the loop

break;

}

//make some surfaces in the name of the variable

for(int q =0; q<numofvar; q++)

{

variable[q] = TTF_RenderText_Solid(font,varstr[q].c_str(),delEquation.at(color_positions[q])->return_color());

Plug_in_variables[q].h=variable[q]->h;

Plug_in_variables[q].w=variable[q]->w;

}

//set the position of the little boxes

for(int q=0; q<numofvar; q++)

{

Plug_in_variables[q].x = Plug_in_box.x + (int)((2*q+1) * (Plug_in_box.w / (2 * numofvar))-(Plug_in_variables[q].w/2));

Plug_in_variables[q].y = Plug_in_box.y + (int)(Plug_in_box.h / 4);

}

cancelstr = "cancel";

cancelsur = TTF_RenderText_Solid(font,cancelstr.c_str(),fontcolor);

cancel.w = cancelsur->w;

cancel.h = cancelsur->h;

cancel.x = Plug_in_box.x + (int)((Plug_in_box.w/2)-(cancel.w/2));

cancel.y = Plug_in_box.y + (int)(2 * Plug_in_box.h/3);

}

std::vector<Digit*> Plug_in_func2(std::vector<Digit*> delEquation)

{

//finish part 3

plug_in_false3();

plug_in_false2();

//get string input in the format x=

return delEquation;

}

};



### #4nobodynews  Members

Posted 01 March 2011 - 08:44 PM

I looked into the assertion that was failing and since you said the problem occurs at the end of main that means you are likely double deleting some memory when a global gets destructed. So look into your global variables and try to find out what might be shared between them that is getting deleted 2+ times.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

### #5Mozly  Members

Posted 01 March 2011 - 09:31 PM

Thanks, You are right.

It stopped showing the error after I got rid of the all the calls to delete in my destructor.

### #6KulSeran  Members

Posted 01 March 2011 - 10:36 PM

Thanks, You are right.

It stopped showing the error after I got rid of the all the calls to delete in my destructor.

That probably happened because you didn't do one of 2 things.
1) drop pointers, and use something like boost::smart_ptr.
2) If you are going to go about it the way you have already, you need to implement operator= and the copy constructor so that you can manually manage the ownership of the pointers.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.