*.c seg fault

a guest Jan 24th, 2020 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. I wanted to describe a computer phenomena I have encountered I haven't found online. It involves code that is functional/segmentation faults based on a chip problem. The technique used is Machine C communicating with the monitor through SDL2, a free kit available online. The mechanism used in this style of code is referred to as 'pointer mechanics'. It can be performed using the following objects:
  3.     //SDL pointers
  4.     SDL_Window *gWindow = NULL;
  5.     SDL_Surface *gScreenSurface = NULL;
  6.     SDL_Surface *gPicture = NULL;
  7.     SDL_PixelFormat *fmt = NULL;
  8.     SDL_Renderer *gRenderer = NULL;
  10. Calls are made to these objects and the images are cast to the screen on a Linux box within an operating system window. This information gets cleared calling a 'close()' function. What happens with this system is fairly interesting because the code works extremely fast. It works so fast, I am not commenting further. However, it is only possible to edit images up to about 200x200 pixels because the following machine calls only successfully store memory at that level. The calls are as follows:
  12.     //load picture from memory
  13.     gPicture = SDL_LoadBMP("/home/computerName/Desktop/targetImage.bmp");
  14.     fmt = gPicture->format;
  15.     int zHt = gPicture->h;
  16.     int zWd = gPicture->w;
  17.     //setup rendering window
  18.     initSDL(zWd,zHt);            //<=== PROFFESSIONALLY TRICKED
  19.     //blit picture to surface
  20.     SDL_BlitSurface(gPicture, NULL, gScreenSurface, NULL);
  22. In order to speed up finding out what has gone wrong/how to extend this method, here is an addition function:
  24. // initialize SDL
  25. void initSDL(int zWd,int zHt) {
  26.     //Init flag
  27.     if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS) < 0) {
  28.         printf("SDL could not initialize: %s\n", SDL_GetError());
  29.     } else {
  30.         //create window
  31.         gWindow = SDL_CreateWindow("SDL Tut",
  33.                 zWd,zHt,SDL_WINDOW_SHOWN);
  34.         //create renderer
  35.         gRenderer = SDL_CreateRenderer(gWindow,-1,0);
  36.         if (gWindow == NULL) {
  37.             printf("Window error: %s\n", SDL_GetError());
  38.         } else {
  39.             //grab surface
  40.             gScreenSurface = SDL_GetWindowSurface(gWindow);
  41.         }                  
  42.     }
  43. }
  45. As per Lazy Fool.
  47. This technique will compile to functioning code below 200x200 (super Thumbnail), but provide a segmentation fault on a Dell Inspiron running Ubuntu 14.04. All code is compiled using 'g++' as it communicates with SDL2 well out-of-the-box. Code has been written using this method that can scale, distort, re-hue, and dither images. Typically the next machine call will be the first function ran on the image, and this is the line of code that will trigger seg faults for a reason I cannot ever figure out or fix.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand