I finally got rid of the segmentation fault. rubynative.h had the problem. When initializing the ruby version of the C++ class, the code was using Data_Make_Struct. While looking over the web I found that other people have trouble with it and C++. I decided to try Data_Wrap_Struct instead. To accomplish that I first create a normal instance of my C++ class using new. Then, I pass the created object to the modified construct(VALUE &object, T *obj) function in rubynative.h :
static T* construct(VALUE &object, T *obj)
{
object = Data_Wrap_Struct(rubyClass(), 0, free, obj);
return obj;
}
Now it works, but the C++ class' destructor is never called so I guess I have a memory leak. However, the ruby script works now using the extension and it actually displays a ball affected by gravity falling into a table. I already coded the feature to allow changing of cameras from ruby and passing of physical parameters through the node's name defined in Irredit. The names now have 3 elements separated by a @ symbol. Here is the whole Ruby script that runs the simulation:
require 'CApp2'
def log string
puts string
end
def parse_params(node_name)
params = node_name.split("@")
end
MASS_IDX = 2
NAME_IDX = 0
PHY_TYPE_IDX = 1
log 'testing CApp2 creation'
app = CApp2.new 800,600, "/Blender/pong_scene.irr"
app.active_nodes_names.each do |name|
params = parse_params(name)
# must use complete name (including the other params
app.init_object(params[PHY_TYPE_IDX].to_i,name, params[MASS_IDX].to_f)
end
app.set_active_camera("my_cam");
app.run();
I am waiting for my GDK project to be approved at sourceforge. My other project, the GameMaker big template, got approved and now is hosted in http://sourceforge.net/projects/gmbigtemplate .
Comments