Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] The Game Tanks. Segmentation error
Qt 6.11 is out! See what's new in the release blog

[Solved] The Game Tanks. Segmentation error

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • 8Observer88 Offline
        8Observer88 Offline
        8Observer8
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • 8Observer88 Offline
          8Observer88 Offline
          8Observer8
          wrote on last edited by
          #4

          How to set the context?

          1 Reply Last reply
          0
          • 8Observer88 Offline
            8Observer88 Offline
            8Observer8
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • 8Observer88 Offline
              8Observer88 Offline
              8Observer8
              wrote on last edited by
              #6

              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]

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved