Regarding the null destination pointer exception
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Regarding the null destination pointer exception

  1. #1
    Join Date
    Dec 2010
    Posts
    617

    Regarding the null destination pointer exception

    Here when NonlinearSolver called the constructor,
    m_gradient() constructor is called to construct m_gradient, which in turns sets a variable called
    m_S to NULL(0), then in the assignment operator, because the m_S is NULL, Visual Studio throws an exception
    saying that destination pointer is null, but it's not fatal. I don't like that to happen because I have to press ignore
    many many times when the program is debugged, how can I fix this bug (not mine) to avoid the null destination pointer exception?
    As an intermediate layer, the function calls boost unbounded array operator = which in turns calls
    std::copy which results in this error
    Thanks
    Jack

    Code:
    NonlinearSolver(solver_type const & solver)  
              : m_gradient()
              , m_function()
              , m_projection()
            {
              *this = solver;
            }
    
            NonlinearSolver(skeleton_type & S)
            {
              this->init(S);
            }
    
            ~NonlinearSolver(){ }
    
            solver_type& operator=(solver_type const &S)
            {
              if(this!= &S)
              {			
    
                this->m_skeleton   = S.m_skeleton;
                this->m_chains     = S.m_chains;
    	    this->m_gradient   = S.m_gradient;
                this->m_function   = S.m_function;
                this->m_projection = S.m_projection;
                this->m_theta      = S.m_theta;
                this->m_H          = S.m_H;
    
                this->m_gradient.init(this);
                this->m_function.init(this);
                this->m_projection.init(this);
              }
              return *this;
            }
    Code:
    template<typename skeleton_type>
          inline NonlinearSolver<skeleton_type>  make_solver( skeleton_type const & skeleton )
          {
            typedef NonlinearSolver<skeleton_type>                solver_type;
            typedef typename solver_type::chain_type              chain_type;
            typedef typename skeleton_type::const_bone_iterator   const_bone_iterator;
            typedef typename skeleton_type::bone_type             bone_type;
    
            solver_type solver; <<<<<<< it calls the default constructor 
    
            solver.init( skeleton );
            const_bone_iterator    bone = skeleton.begin();  
            const_bone_iterator    end  = skeleton.end();
            for( ; bone!=end; ++bone)
            {
              if(!bone->is_leaf())
                continue;
    
              chain_type chain;
              chain.init( skeleton.root(), &(*bone) );
    
              solver.add_chain( chain );
            }
            return solver; <<<<<< it really disgusting because it calls the second constructor of the solver
          }
    Code:
    template<class _InIt,
    	class _OutIt> inline
    	_OutIt copy(_InIt _First, _InIt _Last,
    		_OutIt _Dest)
    	{	// copy [_First, _Last) to [_Dest, ...)
    	_DEBUG_RANGE(_First, _Last);
    	_DEBUG_POINTER(_Dest);
    	return (_Copy_impl(_Unchecked(_First), _Unchecked(_Last),
    		_Dest, _Is_checked(_Dest))); <<< found _Dest to be NULL
    	}
    Last edited by lucky6969b; August 26th, 2014 at 06:45 PM.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,800

    Re: Regarding the null destination pointer exception

    You could use #pragma push_macro to temporarily re-define _DEBUG_POINTER.

    gg

  3. #3
    Join Date
    Dec 2010
    Posts
    617

    Re: Regarding the null destination pointer exception

    I am afraid I still can't stop the debug assertion dialog unless not building with multithreaded debug DLL.
    Really a headache.
    Is the following code correct?
    Thanks Codeplug.
    Jack

    Code:
    solver_type& operator=(solver_type const &S)
            {
    #pragma push_macro(_DEBUG_POINTER)
    #undef _DEBUG_POINTER
              if(this!= &S)
              {			
     
                this->m_skeleton   = S.m_skeleton;
                this->m_chains     = S.m_chains;
       	    this->m_gradient   = S.m_gradient;
                this->m_function   = S.m_function;
                this->m_projection = S.m_projection;
                this->m_theta      = S.m_theta;
                this->m_H          = S.m_H;
    
                this->m_gradient.init(this);
                this->m_function.init(this);
                this->m_projection.init(this);
              }
    #pragma pop_macro(_DEBUG_POINTER)
              return *this;
            }

  4. #4
    Join Date
    Nov 2003
    Posts
    1,800

    Re: Regarding the null destination pointer exception

    I would try re-defining it to do nothing: #define _DEBUG_POINTER(x)

    gg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center