ofxMSAShape3D and "pointer being freed was not allocated"

Hi,

I have a strange bug in ofxMSAShape3D using OF0061, OS X 10.6.3 and Xcode 3.2.1:

My “Star” object has an instance of ofxMSAShape3d and I initialize it from main.c’s setup like this:

  
  
for (int i = 0; i < 2; i++) {  
  myStars.push_back(MyStar());  
  myStars[i].setMap(& myMap);  
  myStars[i].setCursor(& myCursor);  
}  
  

This gives me several of these messages in the console:

  
  
YourMoveDebug(14817,0xa069d4e0) malloc: *** error for object 0xa9e800: pointer being freed was not allocated  
*** set a breakpoint in malloc_error_break to debug  
  

If I only create ONE instance (i.e. setting i < 1) then message disappears. Likewise if I comment out the four lines in ~ofxMSAShape3D() (which I of course don’t want to) the message also disappears.

Is it my limited c++ skills playing tricks with me or have I maybe stumbled upon a real bug?

I have uploaded the full app to http://dl.dropbox.com/u/33406/OpenFrame-…-urMove.zip (about 13mb) if anyone would like to take a look.

Love to all !

Hi, are you extending ofxMSAShape3D? How have you defined MyStar? and how have you defined myStars? The problem you’re having looks like the type of problem you get when deleting an object which is a pointer to base-class but created as a sub-class, where the base-class does not have a virtual destructor. (Confused? see http://blogs.msdn.com/oldnewthing/archi-…-27826.aspx )

I’m guessing if you make the destructor of ofxMSAShape3D virtual, the problem will go away? It had not occurred to me that someone would want to use ofxMSAShape3D in this way so I didn’t make the destructor virtual. A few solutions to your problem (you don’t need to do all of these)

  • make the destructor of ofxMSAShape3D virtual (I’ll include this in the next update)
  • define myStars as a vector of Star instead of ofxMSAShape3D
  • make Star not extend ofxMSAShape3D, instead give it an ofxMSAShape3D property (extend by composition vs extend by inheritance)

Hi Memo,

thank you for your reply. I’m not extending ofxMSAShape3D, I just have a bunch of objects who all has it’s own ofxMSAShape3D for drawing.

I’m crazy busy finishing my report now (uni project deadline friday) so I’ll just submit it with the deconstructor commented out and blame you should they notice :slight_smile: