Memory marking problem

I’m pretty new to Ruby and running into some odd issues with my “mark”
function. Basically I have a situation like this

void ruby_node_free( void* ptr ){
   delete reinterpret_cast<Node*>( ptr );
}
void ruby_node_mark( VALUE self ){
  Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));
  if( ptr ){
    // these are all ruby arrays
    rb_gc_mark( ptr->verts );
    rb_gc_mark( ptr->normals );
    rb_gc_mark( ptr->uvw );
  }
}
void ruby_node_alloc( VALUE klass ){
  Node* ptr = new Node;
  VALUE object = Data_Wrap_Struct( klass, ruby_node_mark, 
ruby_node_free, ptr );
  return( object );
}

What happens is when my ruby_node_mark function is called and I grab the
Node* that value is some chode memory value like 0xfdfdfdfd. I’m
wondering if anyone has run into any problems like this where it seems
that some variables are being deleted twice or something like that.

“J” == Joe B. [email protected] writes:

J> void ruby_node_free( void* ptr ){
J> delete reinterpret_cast<Node*>( ptr );
J> }
J> void ruby_node_mark( VALUE self ){
J> Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));

The mark function take the same argument than the free function, void
*ptr
in your case.

Guy Decoux

ts wrote:

“J” == Joe B. [email protected] writes:

J> void ruby_node_free( void* ptr ){
J> delete reinterpret_cast<Node*>( ptr );
J> }
J> void ruby_node_mark( VALUE self ){
J> Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));

The mark function take the same argument than the free function, void
*ptr
in your case.

Guy Decoux

Thanks - that was it - I don’t know how I managed to breeze by that
glaring error =) Thank you!

Joe