Troubles SDL_UpdateRect()

Hello all!!!
I’m new with SDL.
I’ve been trying to do something extremely simple, so i started to show
an image in my screen, easy…
But when a tried to do the same thing in C++,(the previous thing is done
in plane C), i get troubles.

I have that:

class Painter{
public:
painter(); //Here a put all the functions that starts SDL
~painter(); //SDL_Quit()
void showImage(); //All needed to show the image.

private:
SDL_Surface *screen;

};

When a execute this one, that’s what i get:
The window is pops up and the “full screen mode” too. But when it goes
to SDL_UpdateRect() it crashes and send me that:
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

–>I have checked that if you put in the parameters of
SDL_UpdateRect(screen,0,0,0,0); it does not crash.

–>I have checked also that if you change the prototype of showImage
that way–> void showImage(SDL_Surface *screen); it does not crach either.

My question is:
Is there any trouble in my programing?
is there any bug not yet debugged in SDL?

PD:If anyone wants i can post the whole source

Thnks a lot.

Shanatos.

SDL_UpdateRect(screen,0,0,0,0);
As far as I can remember, that just makes SDL not handle the crash, but
it still crashes. xD
But I could be wrong…

Zakariae El-Abdelouarti Alouaret wrote:> Hello all!!!

I’m new with SDL.
I’ve been trying to do something extremely simple, so i started to show
an image in my screen, easy…
But when a tried to do the same thing in C++,(the previous thing is done
in plane C), i get troubles.

I have that:

class Painter{
public:
painter(); //Here a put all the functions that starts SDL
~painter(); //SDL_Quit()
void showImage(); //All needed to show the image.

private:
SDL_Surface *screen;
};

When a execute this one, that’s what i get:
The window is pops up and the “full screen mode” too. But when it goes
to SDL_UpdateRect() it crashes and send me that:
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

–>I have checked that if you put in the parameters of
SDL_UpdateRect(screen,0,0,0,0); it does not crash.

–>I have checked also that if you change the prototype of showImage
that way–> void showImage(SDL_Surface *screen); it does not crach either.

My question is:
Is there any trouble in my programing?
is there any bug not yet debugged in SDL?

PD:If anyone wants i can post the whole source

Thnks a lot.

Shanatos.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I understood thanks to the wiki that if you put that
SDL_UpdateRect(screen,0,0,0,0) it goes perfect and updates the whole screen.
I must say that i’m using the library SDL_image.

Zaka.

Is there any trouble in my programing?

In this case, probably.

is there any bug not yet debugged in SDL?

Definitely. :slight_smile:

PD:If anyone wants i can post the whole source

Please do. It sounds like it’s not an SDL bug in this case.

–ryan.

Hello again!!

Thanks for the answers.
There are two files attached. The first named “cargar_imagen.cc” is the
first attempt to show a window, get the full screen mode and finally
show one image. It goes perfect, and i put it here to compare it with
the second one. The second file is called “pru_sdl_imagen.cc”, and is a
probe with classes and objects, there is where i had troubles. There are
comments where i think that are problems.

The program is Spanish but it doesn’t matter.

PD:I won’t attach the images but it’s to easy to create one *.tga in
gimp/photoshop, and maybe you all have one in your system.

Thinks.

Shanatos.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: cargar_imagen.cc
Type: text/x-c++src
Size: 1461 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070531/7d002d4b/attachment.cc
-------------- next part --------------
A non-text attachment was scrubbed…
Name: pru_sdl_image.cc
Type: text/x-c++src
Size: 1653 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070531/7d002d4b/attachment-0001.cc

the second one. The second file is called “pru_sdl_imagen.cc”, and is a
probe with classes and objects, there is where i had troubles. There are
comments where i think that are problems.

You had troubles in the first one, too, you just didn’t realize it.

SDL_Rect *dstrect;
dstrect->x = x;
dstrect->y = y;
dstrect->w = imagen->w;
dstrect->h = imagen->h;

“dstrect” is uninitialized here. You probably wanted to do something like:

SDL_Rect dstrect;
dstrect.x = x;
dstrect.y = y;
dstrect.w = imagen->w;
dstrect.h = imagen->h;

…but right now it’s a pointer pointing to random memory instead of an
SDL_Rect. This happened to work in the first program, although it
overwrote some random memory…the other version of the program just
happen to point to something outside your allocated address space.

–ryan.

Make the following changes in the second file:

SDL_Rect dstrect;
dstrect.x = x;
dstrect.y = y;
dstrect.w = imagen->w;
dstrect.h = imagen->h;

The problem is not related to SDL. your original code is:
SDL_Rect *dstrect;
dstrect->x = x;
dstrect->y = y;
dstrect->w = imagen->w;
dstrect->h = imagen->h;

Your dstrect points to nowhere, so you got an segmentation fault.On Thu, 2007-05-31 at 02:49 +0200, Zakariae El-Abdelouarti Alouaret wrote:

Hello again!!

Thanks for the answers.
There are two files attached. The first named “cargar_imagen.cc” is the
first attempt to show a window, get the full screen mode and finally
show one image. It goes perfect, and i put it here to compare it with
the second one. The second file is called “pru_sdl_imagen.cc”, and is a
probe with classes and objects, there is where i had troubles. There are
comments where i think that are problems.

The program is Spanish but it doesn’t matter.

PD:I won’t attach the images but it’s to easy to create one *.tga in
gimp/photoshop, and maybe you all have one in your system.

Thinks.

Shanatos.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

“dstrect” is uninitialized here. You probably wanted to do something like:

(This is true with “sdl_rect” in “dibujar”, too. GCC caught both of
these issues when I enabled warnings and built with optimizations (-Wall
-O3) …Visual Studio and such probably would, too. While it may be
common in a lot of programming projects, if you aren’t using the
compiler warnings, or worse, ignoring them, you do so at your own peril!).

–ryan.

Yes, right what you have said.

I have tried both ways to solve that( initialize the pointer and change
a pointer for a simple structure). It functions perfectly.

My fault.

Thanks guys.

Shanatos.