Access violation in Release only



  • On 10/06/2014 at 02:40, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   13-15 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi,

    I'm really despairing... Win7 x64: Debug version works, Release version breaks with an access violation exception. (Btw: no problems on MacOS) The exception occurs everytime at the same position. It's a simply function that takes a pointer of a point array including point count and an index to calculte a matrix at this point:

      
    Matrix Get_PointMatrix(Vector *pAdr, LONG pcnt, LONG index, Vector up)   
    {   
         Vector p1, p2;   
         Matrix m = Matrix();   
      
         //if (index < 0 || index > pcnt || pcnt > 500 || !pAdr)   
         //     return m;   
                 
    BREAK->     m.off = pAdr[index];   
         if (index < pcnt - 1)   
         p2 = pAdr[index+1];   
              else   
         p2 = pAdr[0];   
         if (index > 0)   
              p1 = pAdr[index-1];   
         else   
              p1 = pAdr[pcnt-1];   
      
         m.v3 = !(p2 - p1);   
         m.v2 = up;   
         m.v1 = -(m.v3 % m.v2);   
         return m;   
    }   
    

    pAdr is 0 at the break point. When I go up the call stack, the values are OK. But I don't know, if I can rely on the displayed values, since I have to run the release version in debug mode.

    Any help is very appreciated!

    Thanks
    Klaus



  • On 10/06/2014 at 06:00, xxxxxxxx wrote:

    Howdy,

    Well, I had similar issues with my plugins and my solution was to back off on the compiler optimization level until I got a stable release. I haven't really noticed any performance issues so far.

    Adios,
    Cactus Dan



  • On 10/06/2014 at 06:12, xxxxxxxx wrote:

    Howdy,

    Here is the old thread about the problems I had with Windows 7 64 bit compiles:
    https://plugincafe.maxon.net/topic/6615/7176_bug-in-baseobjectgetmg&KW=

    Adios,
    Cactus Dan



  • On 10/06/2014 at 07:44, xxxxxxxx wrote:

    Hi Cactus Dan,

    your thread helped very much. Wondering, why the search after "access violation release" on this forum didn't gave me any result.

    Since my problem also occurs on a function, that returns a Matrix, I would bet, that there is a coherence. I will later try to change that function to work with a matrix pointer.

    Switching off optimization for just a small function is also acceptable.

    Regards,
    Klaus



  • On 10/06/2014 at 08:47, xxxxxxxx wrote:

    Howdy,

    Yes, that is interesting that your issue is the same as mine, with the matrix, and with the same versions of Cinema 4D.  😕

    In the end, trying to track down all the offending functions in all of my plugins' code was too time consuming, so I opted for simply turning the optimization off for the whole project.

    Adios,
    Cactus Dan



  • On 11/06/2014 at 07:54, xxxxxxxx wrote:

    Using a matrix pointer instead of the object itself solved the problem for me.

      
    void Get_PointMatrix(Matrix *pMat, Vector *pAdr, LONG pcnt, LONG index, Vector up)   
    {   
         Vector p1, p2;   
      
         pMat->off = pAdr[index];   
         if (index < pcnt - 1)   
              p2 = pAdr[index+1];   
         else   
              p2 = pAdr[0];   
         if (index > 0)   
              p1 = pAdr[index-1];   
         else   
              p1 = pAdr[pcnt-1];   
      
         pMat->v3 = !(p2 - p1);   
         pMat->v2 = up;   
         pMat->v1 = -(pMat->v3 % pMat->v2);   
    }   
    


  • On 11/06/2014 at 09:49, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Using a matrix pointer instead of the object itself solved the problem for me.
    [...]

    That basically points either to a compiler bug (related to inlining your code) or (not so likely) a problem caused by excessive stack usage in the surrounding code - you can check the later by using the analyzer function of VS 2012; it will tell you if methods stack usage exceeds 16 kb (and how much it needs exactly) - although that doesn't catch problems caused by recursive calls using slightly less than 16 kb stack.

    Best regards,

    Wilfried



  • On 12/06/2014 at 02:40, xxxxxxxx wrote:

    Thanks for that experty answer. I'm pretty sure not using so much stack space. I'm working with VS 2010. The previous version of my plugin was compiled with VS 2005 and this problem hasn't occured. So maybe it's really a compiler bug of VS 2010. I'll keep this issue in mind when updating VS.



  • On 12/06/2014 at 05:55, xxxxxxxx wrote:

    May be important question is how do you call this function ?

    > So maybe it's really a compiler bug of VS 2010.
    Of course VS 2010 compiler is not the best one but usually compiler bugs are hidden in more exotic code fragments.



  • On 12/06/2014 at 07:10, xxxxxxxx wrote:

    how do you call this function

    Not sure what you mean. It's not called recursive. It's just that simple service function called from different major functions, that build up some data structures.



  • On 13/06/2014 at 03:09, xxxxxxxx wrote:

    I mean do you call it like this ? :)

      
    Matrix m;  
    Matrix mp = Get_PointMatrix(&m, pcnt, index, up);  
    


  • On 13/06/2014 at 03:34, xxxxxxxx wrote:

    No. The old version at the top of the page didn't need the pointer.

    OLD:

    Matrix m = Get_PointMatrix(pAdr, pcnt, index up);
    

    NEW:

    Matrix m;   
    Get_PointMatrix(&m;, pAdr, pcnt, index up);
    


  • On 13/06/2014 at 07:48, xxxxxxxx wrote:

    Why not use something like this then?
    I think it is better to use reference as pointer.

      
        
        
        	Matrix m;
        	Get_PointMatrix(m, pAdr, pcnt, index, up);
    
      
        
        
        inline void Get_PointMatrix(Matrix &pMat, Vector pAdr[], LONG pcnt, LONG index,const Vector &up) 
        {
        	if(pAdr==nullptr) return;
        	Vector p1, p2; 
         
        	pMat.off = pAdr[index]; 
         
        	if (index < pcnt - 1) p2 = pAdr[index+1]; 
        	else p2 = pAdr[0]; 
         
        	if (index > 0) p1 = pAdr[index-1]; 
        	else p1 = pAdr[pcnt-1]; 
         
        	pMat.v3 = !(p2 - p1); 
        	pMat.v2 = up; 
        	pMat.v1 = -(pMat.v3 % pMat.v2); 
        }
    


  • On 13/06/2014 at 07:56, xxxxxxxx wrote:

    Why? I prefer pointers. In your code, it's hard to distinguish references from objects.



  • On 13/06/2014 at 09:18, xxxxxxxx wrote:

    May be because references are more restricted and this way more safe?
    On can call the function with pointer as a return parameter in a couple of different ways.
    Like this.

      
    Get_PointMatrix(nullptr, pAdr, pcnt, index, up);  
    

    in function like this but with Vector as first parameter, just swap two parameters and you get the problems.

      
    Get_PointMatrix(pAdr, &m, pcnt, index, up);  
    

    Of course this is off-topic now, and of course is "Geschmackssache" :)



  • On 13/06/2014 at 09:48, xxxxxxxx wrote:

    And of course you always test the pointers to be not nullptr !?


Log in to reply