Help needed to debug Ruby C Extension that uses LiveAPI (and Standalone C API)

Hello!

I’ve been reviving an old project to use the LiveAPI. I am running into a very difficult to debug EXC_BAD_ACCESS error.

As a background, my Ruby C Extension:

  • uses the Ruby API for user the interface, then calls a Ruby C Extension method
  • …and on the C-side, takes a “reference” model (this is just a closed skp file)…
  • …takes an “input” model - this is geometry from the model that is open, using the LiveAPI ( takes model from SUApplicationGetActiveModel() )
  • …and smashes them together with C/C++ (cleverly), to create an “output” skp model that is saved to disk
  • …then passes the file path of the output model to SketchUp Ruby, via GetRubyInterface.

My previous old version didn’t use the LiveAPI - it saved the “input” component of the model to disk then did the work in C/C++ as above. It used to work ok-ish, but I wanted to use the LiveAPI to skip the export process (which is done in Ruby).

Having ironed out all the errors I come across, I am stumped on this EXC_BAD_ACCESS error, that comes at the end of my C function (the first line incidentally looks like this:)

VALUE build_from_internal_model(VALUE self, VALUE v_input_model_ptr, VALUE v_input_pid_path, VALUE v_reference_model_path, VALUE v_output_model_path, VALUE su_version);

The runtime CallStack only shows this:

The end of the C function is simply this:

return GetRubyInterface(output_model_path);

… but I think the error occurs after this line, when I believe the local variables from the function is being cleaned up. My hunch is that there is some issue with mixing the stand alone C API with the LiveAPI.

============

One lead I am pulling on is that the Standalone API requires SUInitialize() and SUTerminate() to be called (according to the docs), but the Live C API must NOT call these functions. I have NOT called these functions so I can use the LiveAPI. Is this the correct way? Could my attempt at mixing the Standalone and Live APIs be a cause of the issues?

Another lead I am following is that I have messed up in transferring certain entities from the reference / input models to the output model. For instance, I may have “copied” a material or a layer entitity to the output model from the reference / input model. But what if the entity was attached to the reference/input model, then got added as-is to the output model? i.e I didn’t make a copy, thus an entity was actually attached simultaneously to two models? I would think I’d get better debug information though.

I would be grateful for any pointers on where I should look to get this bug resolved. It looks like it is the last one before I get my extension working with the LiveAPI!

Apologies, having attacked this with a new approach, it turns out that this is a crash on the Ruby API side, not on the C side. I seem not to have my Ruby debugger set up correctly to catch these nicely.

Please consider this resolved!

[Edit: looks like there is no longer any way to get the Ruby debugger working on VSCode anymore….: VSCode Ruby extension no longer mantained - oh dear. This adds time…]

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.