• Advertisement
Sign in to follow this  

Invalid Block type

This topic is 2518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites

class Button
//add mult brac buttons
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;

for(int q=0; q<6;q++)
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_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;

//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())
if(matches ==0)//if there are no matches it is a new var
varstr[var_comparator] = delEquation.at(q)->return_svalue();

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

//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());


//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

//get string input in the format x=
return delEquation;

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Thanks, You are right.

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

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement