[Solved] The Game Tanks. Segmentation error



  • Hello

    I have the Segmentation error on the line: m_textures.push_back( new QOpenGLTexture( frame ) );

    When I press "the Space key":

    [CODE]void ExplosionOfProjectile::genTextures()
    {
    QImage image( ":/Texture/TankSpriteSheet.png" );
    image = image.mirrored( false, true );

    QImage frame;
    
    frame = image.copy( 257, 112, 15, 15 );
    m_textures.push_back( new QOpenGLTexture( frame ) );
    
    frame = image.copy( 272, 112, 16, 16 );
    m_textures.push_back( new QOpenGLTexture( frame ) );
    
    frame = image.copy( 287, 111, 18, 18 );
    m_textures.push_back( new QOpenGLTexture( frame ) );
    

    }
    [/CODE]

    Source: https://github.com/8Observer8/Tanks



  • Hi,

    Please look at the second paragraph in the documentation of the "constructor":http://doc.qt.io/qt-5/qopengltexture.html#QOpenGLTexture-2 you are using. Maybe that's the issue.



  • Thank you

    bq. This does create the underlying OpenGL texture object. Therefore, construction using this constructor does require a valid current OpenGL context.

    But it works with object of the Tank class? This is a same situation with the "Tank" class



  • How to set the context?



  • It was bacause I had mistake. I replace "Texture" on "Textures". But now there is a new crash

    I set breakpoing on "update()" method but after "continue" I have crash:

    [CODE]void Scene::addProjectileExplosion( float x0, float y0 )
    {
    ExplosionOfProjectile *explosion = new ExplosionOfProjectile( &m_program, m_vertexAttr, m_textureAttr, m_textureUniform );
    explosion->setX0( x0 );
    explosion->setY0( y0 );
    connect( explosion, SIGNAL( signalShowProjectileExplosion( int, bool ) ),
    this, SLOT( slotShowProjectileExplosion( int, bool ) ) );
    m_projectileExplosions[explosion->id()] = explosion;
    explosion->start();

    update();
    

    }[/CODE]

    https://github.com/8Observer8/Tanks



  • I solved the problem: [url]https://github.com/8Observer8/Tanks[/url]

    The Error:

    @for ( auto iterOfProjectile = m_projectiles.begin(); iterOfProjectile != m_projectiles.end(); ++iterOfProjectile )
    {
                    ....
                    m_projectiles.erase( iterOfProjectile );
                    addProjectileExplosion( x0, y0 );@
    

    The Solution:

    @auto iterOfProjectile = m_projectiles.begin();
    

    // for ( auto iterOfProjectile = m_projectiles.begin(); iterOfProjectile != m_projectiles.end(); ++iterOfProjectile )
    while (iterOfProjectile != m_projectiles.end())
    {
    Projectile *projectile = iterOfProjectile->second;

        float x0 = projectile->x0();
        float y0 = projectile->y0();
    

    bool doDel = false;

        switch ( projectile->direction() ) {
            case Projectile::Up:
                projectile->setY0( projectile->y0() - step );
                doDel = projectile->y0() <= 0.0f;
                break;
            case Projectile::Left:
                projectile->setX0( projectile->x0() - step );
                doDel = projectile->x0() < 0.0f;
                break;
            case Projectile::Down:
                projectile->setY0( projectile->y0() + step );
                doDel = projectile->y0() >= ( m_canvasHeight - projectile->height() );
                break;
            case Projectile::Right:
                projectile->setX0( projectile->x0() + step );
                doDel = projectile->x0() > ( m_canvasWidth - projectile->width() );
                break;
        }
    

    if (doDel )
    {
    delete projectile;
    m_projectiles.erase( iterOfProjectile++ );
    addProjectileExplosion( x0, y0 );
    }
    else
    iterOfProjectile++;
    }@

    I am helped [URL="http://www.prog.org.ru/index.php?topic=28254.msg206472#msg206472"]here[/URL]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.