What's new

[C/SDL] Linux Programming trouble


Plugin coder / Betatester

For some school exercise I need to draw lines between two points
by calculating the pixels between x,y and x1,y1.
(x0 and y0 is a midpoint)

Normally I program in MSVC7 (and in C++), but for this exercise programming
needs to be done in Linux using C and SDL.

My main problem is as following:

Below you can see a part of my sourcecode

C code:
void drawline(SDL_Surface *s, int x0, int y0, int x1, int y1, Uint32 colour) {
// Seems like KDevelop is a bit picky on not used variables.
  printf("x0 %d ",x0);
  printf("y0 %d ",y0);
  printf("x1 %d ",x1);
  printf("y1 %d \n",y1);

// size from midpoint
int dx = x1 - x0;
int dy = y1 - y0;

// most left pixel
int x = x0 - dx;
int y = y0 - dy;

// slope x
float dydx = ((float)y/(float)x);
printf("dydx %f ",dydx);

// slope y
int i_dydx = (int)round(dydx);
printf("dydx %d \n",i_dydx);

// draw
   // y++;

Whenever i do smth with the y value in the while loop. I get the following error message:
error msg:
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
So i've commented it temporarly.

Any clue what could be wrong?


are you sure you always pass x0 < x1 and y0 < y1 ??? if x0 > x1 x will be the pixel in the right ( but it won't draw anything because of the loop condition ) if y0 > y1 you will draw a different line

I don't know but try to printf y value in the loop
Last edited:


New member
Looks like 'y' is going out of range, so PutPixel tries to access memory in the surface which is not there -> segmentation fault (unhandled exception)