1 Reply Latest reply on Jan 18, 2007 4:10 PM by Sonic2004

    Memory leak using dynamically created primitive model

    Sonic2004
      Hey there folks. I know there is another post similar to this one, but there are some differences in my problem. Here are some things you should know.
      All of my 3D objects are dynamically created and must be because all objects are user defined and unique. These objects change during each run and there is no way to predict what they will be.
      Every object I create except for the sphere prim is a custom mesh object.
      Essentailly, this is what is happening. When any of the sphere objects are in the viewing plane of the camera a memory leak of around 16K occurs about every second from what I can tell. I have not tested to see if increasing or decreasing the frame rate would have any effect on this. Over time this eventually causes Shockwave/Projector to crash considering this application may be run for days. Interestingly enough, when I change the #facing param when creating the model resource from #both to either #back or #front the amount of memory and interval decrease by half. Doing this has no effect on any other shape.
      As I mentioned before the sphere shape is the only one I create via the standard primitives. What I did to create a mesh was to create the model resource, the model, and then use meshDeform to grab the faceList and vertexList from the model and create a mesh. This did nothing useful for me as the leak still exists. Here is the code for that little snippet.

      -- Create the model resource
      modelResourceO = me.createHemisphereResource(pHemisphereID, lUnits, 10, 0, 180)

      on createHemisphereResource(me, vHemisphereID, vHemisphereRadius, vResolution, vStartAngle, vEndAngle)
      -- Create a new model resource
      if (wrld.modelResource(vHemisphereID) = void) then
      mRes = wrld.newModelResource(vHemisphereID, #sphere, #front)
      mRes.radius = vHemisphereRadius
      mRes.resolution = vResolution
      mRes.startAngle = vStartAngle
      mRes.endAngle = vEndAngle

      return mRes

      end if

      end createHemisphereResource

      -- Use this to create the Hemisphere model with the mesh reference
      on createHemisphereModel(me, vModelName, vMeshRef)
      modelO = wrld.newModel(vModelName & "_model", vMeshRef)

      -- Just a test
      modelO.addModifier(#meshDeform)
      lFaces = modelO.meshDeform.face.count
      lVerts = modelO.meshDeform.mesh[1].vertexList.count
      meshO = wrld.newMesh(vModelName & "_mesh", lFaces, lVerts)
      meshO.vertexList = modelO.meshDeform.mesh[1].vertexList
      repeat with f = 1 to lFaces
      lFace = modelO.meshDeform.mesh[1].face[f]
      meshO.face[f].vertices = lFace

      end repeat
      meshO.generateNormals(#smooth)
      meshO.build()

      modelO.removeFromWorld()
      wrld.deleteModelResource(vModelName)
      wrld.deleteModel(vModelName & "_model")

      modelO = wrld.newModel(vModelName & "_model", meshO)

      return modelO

      end createHemisphereModel

      So, finally to my questions. Has anyone experienced any continuous leaks on dynamically created prims? If so, have you found a way to get passed this? I could just create a mesh as I did the other objects, but that is essentially what I am doing as I am just copying the vertexList and faceList and creating a mesh from scratch. With that, why would it act any differently from the other meshs? Could there be something in the vertexList or faceList that might cause this, or am I looking at this incorrectly?
      Any thoughts or comments is greatly appreciated.

      Thank you in advance,
      Dave
        • 1. Re: Memory leak using dynamically created primitive model
          Sonic2004 Level 1
          Well, it looks as though this was related to reallocating my shaders on the fly. Once the object is created there is a process that will change the shader on the fly if certain parameters are met. When this occurs the memory leak starts up right away. If I apply the same shader immediately and not after removing the previous one and adding it, it works fine. Anyone have any clue to why this happens?