Error trying to load an image with sdl2_image and c ++, (segmentation faul core dumped)

2

I have tried to load an image in sdl2 and just when I use sdl_image I get an error ( segmeentation fault core dumped ). Only there gives me error everything else seems to work well.

These are the libraries corresponding to sdl2

#include<SDL2/SDL.h>
#include<SDL2/SDL_events.h>
#include<SDL2/SDL_image.h>

These are the libraries corresponding to c ++

#include<stdio.h>
#include<iostream>
#include<string.h>

using namespace std;

SDL_Window   *ventana; // declaracion de una variable para LA VENTANA
SDL_Renderer *render;  // declaracion de una variable para RENDERIZAR
SDL_Texture  *textura; // declaracion de una variable para TEXTURA
SDL_Surface  *img;     // declaracion de una SUPERFICIE PARA LA IMAGEN

int main()  {

  // AQUI SE CREA UNA VENTANA DE 640 POR 480 LLAMADA "PRUEBA"   
  ventana = SDL_CreateWindow("prueba",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN);

  // AQUI SE COMPRUEBA SI LA VENTANA ES CREADA CORRECTAMENTE
  if(ventana==NULL)
  {
    printf("error en ventana %s\n",SDL_GetError());
  }
  else
  {
    // SI LA VENTANA SE CREA CORRECTAMENTE SE HACE EL RENDERIZADO
    render=SDL_CreateRenderer(ventana,-1,SDL_RENDERER_ACCELERATED);
    if(render==NULL)
    {
      printf("error en render %s\n",SDL_GetError());
    }
    else
    {
      // SI EL RENDERIZADO TIENE EXITO SE CREA UN COLOR PARA EL RENDERIZADO
     SDL_SetRenderDrawColor(render,0xff,0xff,0xff,0xff);

     // SE INICIA SDL2_IMAGE PARA CARGAR UNA IMAGEN FORMATO PNG 
     int flag=IMG_INIT_PNG;
     if(!(IMG_Init(flag)&flag))
     {
       printf("error en imginit %s\n",IMG_GetError());
     }
     else
     {
       // SI SE TIENE EXITO INICIANDO SDL2_IMAGE SE PROCEDE A CARGAR
       // LA IMAGEN
       // JUSTO AQUI OCURRE EL ERROR SOLO COLAPSA SIN ARROJAR MENSAJE
       // DE  ERROR NI NADA
       // SOLO UN SEGMENTATION FAULT CORE DUMP SI COLOCO DOBLE SLASH A
       // ESTE FRACMENTO DE CODIGO EL CORE DUMP DESAPARECE Y SE CARGA LA
       // VENTANA CON EL COLOR BLANCO DE FONDO DEL RENDERIZADO ASI ME DI
       // CUENTA QUE EL ERROR SOLO ESTA EN ESTA LINEA
       img=IMG_Load("awesome_pot__x1_broken_png_1354830342.png");
       if(img==NULL)
       {
         printf("error en img load %s\n",IMG_GetError());
       }
       else
       {
         // DE CARGARSE CORRECTAMENTE LA IMAGEN SE PROCEDE A CREAR UNA
         // TEXTURA EN BASE A LA IMAGEN
         textura=SDL_CreateTextureFromSurface(render,img);
         if(textura==NULL)
         {
           printf("error en textura %s\n",SDL_GetError());
         }
         else
         {
           // UNA VEZ UTILIZADA LA IMAGEN PARA CREAR LA TEXTURA ESTA
           // PUEDE SER ELIMINADA
           SDL_FreeSurface(img);

           // AQUI SE COLOCA EL RENDER DE COLOR BLANCO
           SDL_RenderClear(render);

           // AQUI ES DONDE SE COPIA EL RENDER Y LA TEXTURA EN PANTALLA
           // SIN MOSTRAR LA PANTALLA       
           SDL_RenderCopy(render,textura,NULL,NULL);

           // AQUI FINALMENTE SE MUESTRA LA IMAGEN EN PANTALLA
           SDL_RenderPresent(render);

           // ESTE ES UN RETRASO PARA QUE EL PROGRAMA CORRA POR 2
           // SEGUNDOS 
           SDL_Delay(2000);

           // FINALMENTE SE CIERRA SDL Y EL SDL_IMAGE
           IMG_Quit();
           SDL_Quit();

           // ESTAS LLAVES CORRESPONDEN A LAS SENTENCIAS IF DE ARRIBA
         }//render
       }//img_init
     }//imgload
   }//textura
 }//ventana
    
asked by Manuel Naim 22.03.2016 в 21:45
source

1 answer

0

Fix it, I was forced to reinstall sdl2 image , apparently something went wrong when installing it.

I really do not know what went wrong when installing it but somehow when I installed it with the synaptic package manager some installation error must have occurred.

To correct the problem I did the following:

  • Download sdl2_image from the page - > link and download the name package - > SDL2_image-2.0.1.tar.gz.
  • 2. Enter the terminal as a super user and enter the download folder using the cd command.

    3 Once in the download folder, go to the sdl2_image folder and copy ./configure.

  • When I finish the execution of ./ configure enter the command make all.

  • At the end of make all, enter the make install command . and ready problem solved.

  • Somehow installing it step by step corrected the error generated after installing it by the package manager.

        
    answered by 30.03.2016 / 15:31
    source