c# - Passing Structures between Managed and Unmanaged Code -


i call c++/cli method c# in method:

        bool setproperty(element element, node referencepoint, list<materializer> materializers, list<ulong> properties)     {          // loop on stls         (int = 0; < materializers.count; i++)         {                            materializer materializer = materializers[i];             pentaltreenode pentaltreeroot = pentaltreedatasets[i].top;               if (materializer.ispointinside(referencepoint.x, referencepoint.y, referencepoint.z, pentaltreeroot))             {                 element.propertyid = properties[i];                 return true;             };          }          return false;     } 

c++/cli method this:

bool ispointinside(double x, double y, double z, pentaltreenode ^root)     {         int intersectioncount = 0;          math3d::m3d raypoints[2], intersectionpoint;          raypoints[0].set(x,y,z);         raypoints[1].set(x,y,1.0e6);           if(_box->iscontainingpoint(x,y,z))         {                        intersectioncount=countintersects(x,y,z,root);             return (intersectioncount%2!=0);          }         } 

what wrong, because c++/cli method doesn't return same result? how pin or marshal?

method in c++/cli(maybe not ok?):

int countintersects(double x, double y, double z, pentaltreenode ^root)     {          math3d::m3d raypoints[2], intersectionpoint;          raypoints[0].set(x,y,z);         raypoints[1].set(x,y,1.0e6);          if(!root)              return 0;         else         {             int special = countintersects(x,y,z,root->special);             if (x <= root->xmax && x >= root->xmin && y <= root->ymax && y >= root->ymin)             {                  if( _stlmesh->israyintersectspoly(root->index, raypoints, intersectionpoint))                 {                     return (1 + special);                 }                 else                      return special;             }             else             {              if (y>root->ymax)               {                     return (countintersects(x,y,z,root->top)+special);               }               else if(y<root->ymin)                     {                         return (countintersects(x,y,z,root->bottom)+special);                     }                     else if(x<root->xmin)                             {                                 return (countintersects(x,y,z,root->left)+special);                             }                             else if(x>root->xmax)                             {                                 return (countintersects(x,y,z,root->right)+special);                             }                             else                                  return special;             }          }      } 

if( _stlmesh->israyintersectspoly(root->index, raypoints, intersectionpoint)) 

there's 1 possible flaw in particular statement, you've never initialized intersectionpoint. c++ lets away this, doesn't have similar c#'s definite assignment rules. isn't 100% clear whether that's real problem, variable might passed reference.

in debug build, such uninitialized variable have predictable value. can see in debugger when switch hexadecimal display mode. fields in struct or class contain value 0xcccccccc, value that's apt generate nonsensical results or crash code access violation. in release build, /rtc option isn't turned on , you'll entirely random values in variable.

which corresponds description of problem, high odds indeed problem. sure use debugger find problems this, can see value of local variables autos debugger window single-step through code.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -