Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    NewMem question

    Cinema 4D SDK
    2
    6
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      ello
      last edited by s_bach

      in my plugin i used the following code which doesn't work in r20

      Vector* vp1 = NewMem(Vector, 3);
      Vector* vp2 = NewMem(Vector, 3);
      Vector* vf = NewMem(Vector, 3);
      

      i get the error "Initialisierung": "maxon::ResultMemT<T *>" kann nicht in "Vector *" konvertiert werden

      edit: found out this

      Vector vp1[3] = { endpoint1 + dir * Vector(0, 0, -20) , endpoint1 + dir * Vector(0, 5, -5) , endpoint1 + dir * Vector(0, -5, -5) };
      

      but now i get new errors:

      Fehler (aktiv) E0135 "class "maxon::ArrayInterfacemaxon::Generic"" hat keinen Member ""Iterator"". arkos C:\sdk\frameworks\core.framework\source\maxon\array.h 741

      Fehler (aktiv) E0070 Ein unvollständiger Typ ist nicht zulässig. arkos C:\sdk\frameworks\core.framework\source\maxon\array.h 706

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        Cinema 40 R20 introduces a new, elaborate error handling system. A function can return now a dedicated result object that stores additional information if the operation was successful or not.

        NewMem does return such a result value. You find information on how to handle errors in the documentation: Error Handling. See also Error System in the API Transition.

        That being said, in most cases there should be no reason to allocate memory with NewMem. It is recommended to use arrays like BaseArray instead. Such an array provides save access to and management of the allocated data.

        See

        • Memory Allocation
        • BaseArray Manual

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        E 1 Reply Last reply Reply Quote 4
        • E
          ello @s_bach
          last edited by

          @s_bach thank you very much for pointing me to that. however, i tried adopting that to a function retrieveing the vertex normals and now i don't know how to properly return those normals.

          Vector *GetVertexNormals(PolygonObject *pObj)
          {
          	Int32 numVerts = pObj->GetPointCount();
          	Int32 numPolys = pObj->GetPolygonCount();
          	const Vector *pVerts = pObj->GetPointR();
          	const CPolygon *pPolys = pObj->GetPolygonR();
          
          	// initialize neighbor class... this is used to compute m_SrcvNorms
          	Neighbor neighbor;
          	if( !neighbor.Init(numVerts, pPolys, numPolys, NULL) )
          		return NULL;
          
          	//** those two lines worked in the old version **//
          	//Vector *pNormals = (Vector *)NewMemClear(UChar,numVerts * sizeof(Vector));
          	//if( !pNormals )     return NULL;
          
          	//** these are my adoption to basearray **//
          	maxon::BaseArray<Vector> pNormals;
          	if(pNormals.GetCount()<=0) return NULL;
          
          	// Determine a Normal for each vertex of mesh
          	Int32 i, j, faceCnt, *pFaces = NULL;
          	Vector vNorm;
          	for(i=0; i<numVerts; i++)
          	{
          		vNorm = Vector();          // (re)intitialize 
          		neighbor.GetPointPolys(i, &pFaces, &faceCnt);
          		if( faceCnt )
          		{
          			for(j=0; j<faceCnt; j++)
          			{
          				Vector n = CalcFaceNormal(pVerts, pPolys[pFaces[j]]);
          				vNorm += !n;
          			}
          			vNorm /= faceCnt;          // average the normal(s)
          			pNormals[i] = !vNorm;     // normalize and store
          		}
          		else
          			pNormals[i] = Vector(0.0,1.0,0.0);     // default case = Up for any stray verts
          	}
          	return pNormals;
          }
          
          S 1 Reply Last reply Reply Quote 0
          • E
            ello
            last edited by

            and btw, it seems to be a general problem with all parts of the plugin, cinema is not crashing with most of them, but the debugger halts everytime

            1 Reply Last reply Reply Quote 0
            • S
              s_bach @ello
              last edited by

              Hello,

              the best solution is probably to create the BaseArray in the caller and hand over a reference to that BaseArray. Your function can then safely fill the BaseArray:

              maxon::Result<void> GetVertexNormals(PolygonObject * const pObj, maxon::BaseArray<Vector>& normals)
              

              If you encounter unexpected break points, please open a new thread to discuss this issue.

              best wishes,
              Sebastian

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 3
              • E
                ello
                last edited by

                thank you. i got this working. maybe there are even other places in my code where i can use this knowledge 🙂

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post