A bug or it's my fault?

Hi all,

Well I have a problem doing that:

typedef struct {
Uint8 button;
Uint16 x,y;
}QML_Mouse;

QML_Mouse *QML_GetMouseClickEvent (void)
{
SDL_Event event;

while (SDL_WaitEvent(&event) >= 0)
{
switch(event.type)
{
case SDL_MOUSEBUTTONDOWN:
{
QML_Mouse *mouse;
Uint8 m_button;
Uint16 m_x, m_y;

/* THIS works fine */
    m_button = event.button.button;
    m_x = event.button.x;
    m_y = event.button.y;
/* --------------  */
         
   /* I GET Fatal signal: Segmentation Fault (SDL Parachute

Deployed) DOING the following : /
/

!!!
*/

   mouse->button = m_button; 
   mouse->x = m_x;
   mouse->y = m_y;
  /*--------------------------------------------------------------------------------------

*/

 #if defined DEBUG
 fprintf(stderr, "QML: mouse button %d, pressed at x: %d, y: %d\n",

m_button, m_x, m_y);
#endif

 return mouse;
}

}
}
return NULL; /* NO COMPLAIN */
}

I’m using SDL 1.1.3

Thanks.

  • @G.Gabriele ---------------+
    | |
    ±----------------- think Open Source -+

Well, you just define a ‘pointer’ to a QML_Mouse structure.
That points after the declaration into nirvana.

Try allocation of a real structure. :wink:

Like:
QML_Mouse mouse = (QML_Mouse)alloc(sizeof(QML_Mouse));

But beware you have to free the allocated memory after using the struct.

Or you just pass a pointer to a static declared structure, like:

static QML_Mouse mouse;
.
.
mouse.button = m_button;
mouse.x = m_x;
mouse.y = m_y;
.
.
return &mouse

Hope that helps :wink:

Alex

“G.Gabriele” wrote:> Hi all,

Well I have a problem doing that:

typedef struct {
Uint8 button;
Uint16 x,y;
}QML_Mouse;

QML_Mouse *QML_GetMouseClickEvent (void)
{
SDL_Event event;

while (SDL_WaitEvent(&event) >= 0)
{
switch(event.type)
{
case SDL_MOUSEBUTTONDOWN:
{
QML_Mouse *mouse;
Uint8 m_button;
Uint16 m_x, m_y;

    /* THIS works fine */
    m_button = event.button.button;
    m_x = event.button.x;
    m_y = event.button.y;
    /* --------------  */

   /* I GET Fatal signal: Segmentation Fault (SDL Parachute

Deployed) DOING the following : /
/

!!!
*/

   mouse->button = m_button;
   mouse->x = m_x;
   mouse->y = m_y;
  /*

*/

 #if defined DEBUG
 fprintf(stderr, "QML: mouse button %d, pressed at x: %d, y: %d\n",

m_button, m_x, m_y);
#endif

 return mouse;
}

}
}
return NULL; /* NO COMPLAIN */
}

I’m using SDL 1.1.3

Thanks.

  • g.gabriele at europe.com ---------------+
    | |
    ±----------------- think Open Source -+

I think you need to allocate *mouse before you try to use it.
Something like:
mouse = (QML_Mouse *) malloc ( sizeof (QML_Mouse) );

cheers,
Dave “PenguinDude” Archbold> -----Original Message-----

From: G.Gabriele [SMTP:netbone at tiscalinet.it]
Sent: Tuesday, August 08, 2000 1:49 PM
To: sdl at lokigames.com
Subject: [SDL] A bug or it’s my fault ?

Hi all,

Well I have a problem doing that:

typedef struct {
Uint8 button;
Uint16 x,y;
}QML_Mouse;

QML_Mouse *QML_GetMouseClickEvent (void)
{
SDL_Event event;

while (SDL_WaitEvent(&event) >= 0)
{
switch(event.type)
{
case SDL_MOUSEBUTTONDOWN:
{
QML_Mouse *mouse;
Uint8 m_button;
Uint16 m_x, m_y;

/* THIS works fine /
m_button = event.button.button;
m_x = event.button.x;
m_y = event.button.y;
/
-------------- */

   /* I GET Fatal signal: Segmentation Fault (SDL Parachute

Deployed) DOING the following : /
/

!!!
!!!
*/

   mouse->button = m_button; 
   mouse->x = m_x;
   mouse->y = m_y;
  /*


*/

 #if defined DEBUG
 fprintf(stderr, "QML: mouse button %d, pressed at x: %d, y: %d\n",

m_button, m_x, m_y);
#endif

 return mouse;
}

}
}
return NULL; /* NO COMPLAIN */
}

I’m using SDL 1.1.3

Thanks.

  • g.gabriele at europe.com ---------------+
    | |
    ±----------------- think Open Source -+

Alexander Pipelka wrote:

Well, you just define a ‘pointer’ to a QML_Mouse structure.
That points after the declaration into nirvana.

Try allocation of a real structure. :wink:

Like:
QML_Mouse mouse = (QML_Mouse)alloc(sizeof(QML_Mouse));

But beware you have to free the allocated memory after using the struct.

Or you just pass a pointer to a static declared structure, like:

static QML_Mouse mouse;
.
.
mouse.button = m_button;
mouse.x = m_x;
mouse.y = m_y;
.
.
return &mouse

Hope that helps :wink:

Alex

Great, thanks a million :wink: