0

私はC++で奇妙な問題を抱えています:

uint8_t*クラスの初期化子リストでを新しくしたいときに、プログラムがクラッシュしPixelIteratorます。

コールスタックは次のとおりです。

#0 00000000 0x0040b030 in __cxa_throw() (??:??)
#1 00000000 0x004047e1 in operator new() (??:??)
#2 004018B5 PixelIterator(this=0x28fe2c, _oth=0x5d5154, iOffset=300, iPitch=300, iBpp=2 '\002') (C:\Users\David\Desktop\SDL++\SDLPP_Sprite.cpp:34)
#3 0041E0CC SDL::Sprite::At(this=0x5d1548, iX=150, iY=0) (C:/Users/David/Desktop/SDL++/SDLPP_Sprite.hpp:89)
#4 0041E5B0 MyApp::OnInit(this=0x5d1520, iArgc=1, ppcArgv=0x5d1498) (C:\Users\David\Desktop\SDL++\main.cpp:37)
#5 00402641 SDL::Application::Run(this=0x5d1520, pScreen=0x5d4df0, iArgc=1, ppcArgv=0x5d1498) (C:\Users\David\Desktop\SDL++\SDLPP_Application.cpp:24)
#6 004020A3 main(iArgc=1, ppcArgv=0x5d1498) (C:\Users\David\Desktop\SDL++\main.cpp:103)

まず第一に、PixelIteratorクラスはから継承しBaseIteratorます:

template< typename T >
class BaseIterator
{
public:
    typedef T ValueType;

    BaseIterator( void )
        :   ptr( NULL )
    {}

    BaseIterator( const BaseIterator< T >& _oth )
        :   ptr( _oth.ptr )
    {}

    BaseIterator( T * p )
        :   ptr( p )
    {}

    T& operator*( void )
    {
        assert( ptr != NULL );
        return *ptr;
    }

    T* operator->( void )
    {
        assert( ptr != NULL );
        return ptr;
    }

    bool operator==( const BaseIterator< T >& _oth )
    {
        return ptr == _oth.ptr;
    }

    bool operator!=( const BaseIterator< T >& _oth )
    {
        return ptr != _oth.ptr;
    }

    bool operator<( const BaseIterator< T >& _oth )
    {
        return ptr < _oth.ptr;
    }

    bool operator<=( const BaseIterator< T >& _oth )
    {
        return ptr <= _oth.ptr;
    }

    bool operator>( const BaseIterator< T >& _oth )
    {
        return ptr > _oth.ptr;
    }

    bool operator>=( const BaseIterator< T >& _oth )
    {
        return ptr >= _oth.ptr;
    }

    friend ostream& operator<<( ostream& _os, const BaseIterator< T >& _this )
    {
        _os << reinterpret_cast< void* >( _this.ptr );
        return _os;
    }

protected:
    T * ptr;
};

そしてここにPixelIteratorクラスがあります:

/**
 **  Designed to iterate through a virtual 2D array of pixels( uint8_t* )
 **/
class PixelIterator : public BaseIterator< uint8_t* >
{
public:
    PixelIterator( void );
    PixelIterator( const PixelIterator& _oth );
    PixelIterator( uint8_t ** _oth, uint32_t iOffset, uint16_t iPitch, uint8_t iBpp );
    ~PixelIterator( void );

    PixelIterator& operator=( const PixelIterator& _oth );

    PixelIterator& operator++( void ); // 1 pixel right
    PixelIterator& operator--( void ); // 1 pixel left
    PixelIterator& operator++( int unused ); // 1 pixel right
    PixelIterator& operator--( int unused ); // 1 pixel left

    PixelIterator& operator+=( uint32_t iSize ); // iSize pixel right
    PixelIterator& operator-=( uint32_t iSize ); // iSize pixel left

    PixelIterator& operator>>( uint32_t iSize ); // iSize pixel down
    PixelIterator& operator<<( uint32_t iSize ); // iSize pixel up

protected:
    uint16_t m_iPitch;
    uint8_t m_iBpp;
};

そして、これはエラーが発生するコンストラクターです。

Sprite::PixelIterator::PixelIterator( uint8_t ** _oth, uint32_t iOffset, uint16_t iPitch, uint8_t iBpp )
    :   BaseIterator< uint8_t* >( new uint8_t*( *_oth + iOffset ) ),
        m_iPitch( iPitch ),
        m_iBpp( iBpp )
{}

_othこの場合、ピクセルデータへのポインタへのポインタです(1D配列のvoid*); iOffset配列内のオフセットです

グラフィック出力にSDLを使用し、IDEとしてCode::Blocksを使用しています。テストされた画像のサイズは150x120ピクセルです。

コードに関する詳細情報が必要な場合は、お問い合わせください:)

編集:

インスタンス化:

m_Img.Lock();
for( int32_t y = 0; y < m_Img.GetSurface()->h; y++ )
{
    for( SDL::Sprite::Iterator x = m_Img.At( 0, y ); x != m_Img.At( m_Img.GetSurface()->w, y ); x++ )
        *reinterpret_cast< uint16_t* >( *x ) = 0;
}
m_Img.Unlock();

SDL::Sprite::IteratorSDL::Sprite::PixelIterator( )と同じtypedefです。 m_ImgのオブジェクトですSDL::Sprite

SDL::Sprite::At()方法:

inline
Iterator At( uint32_t iX, uint32_t iY )
{
    return Iterator( reinterpret_cast< uint8_t ** >( &m_pSurface->pixels ),
                     iY * m_pSurface->pitch + iX * m_pSurface->format->BytesPerPixel,
                     m_pSurface->pitch, m_pSurface->format->BytesPerPixel );
}

m_pSurface上のポインタですSDL_Surface

4

0 に答える 0