A call to freeobjects() clears modifier and object tables

Hi All (but mostly Greg),

I wrapped rtrace into c++ singleton class to provide an interface for dynamic calls calls to rtrace without reloading the scene each time. Additionally I am adding the light sources (sky and/or sun(s)) after the main octree is built so they will live at the end of the object list. This way I can pop them off using freeobjects() and then add new sources (again, without reloading the scene, I only need to reinitialise the ambient cache). This was all working swimmingly until I tried to render a scene with a mixfunc:

fatal - undefined modifier "f" for mixfunc "glz"

This is when I discovered that the call to clearobjndx() within freeobjects() completely resets the modifier and object tables, explaining the error I get when mixfunc cannot find its component modifiers.

To get around this for now, I have done this (where nobjs is the argument passed to freeobjects():

/* EDIT: Don't free tables if only removing a few objects
this probably means we want to use them again */
if (nobjs > 10)

This is obviously not a very good solution. so my questions are:

  • Is there a simple way to only clear the relevant items in the table?
  • Or, since later entries always take precedence, is it actually necessary to clear the modifier table ever?
  • What is the object table used for? I am surprised I haven’t encountered any issues sooner with these to tables completely reinitialised. Would this be an issue if I had a mesh in my scene?
  • Should I just make a new function (free_some_objects()) that omits the clearobjindx() call, and only use freeobjects() when I really want to clear everything?

Gotta love these Saturday morning challenge questions!

This is indeed a bug in that routine, and something I had not encountered as I generally free all of the objects if I’m freeing any of them.

It took me a while to figure out the right thing to do, as there’s no easy way to delete solitary entries from the modifier hash table, due to the rehashing scheme I’m using. However, there’s no problem clearing out all table entries above a certain index, so I changed the code to handle that case correctly. Try the newly checked in modules in src/common to see if this doesn’t correct your problem.

thanks greg!

It turns out skipping the clearobjindx() was causing a segfault the second time I tried to add a new source.