Skip navigation.
Home
The QNX Community Portal

View topic - PtSendEventToWidget memory violation

PtSendEventToWidget memory violation

Isn't the name clear?

PtSendEventToWidget memory violation

Postby VincentOx » Tue May 05, 2009 9:11 am

Hi,

i have a problem using the method PtSendEventToWidget. It seems to be a memory violation access problem. In fact, to be able to call this method without having a crash due to memory violation, we have to declare previously an unused char variable. It seems that this memory offset is necessary; but why ?!

Here is the part of the code in which the problem is met:

Code: Select all
int testCallbackButton(PtWidget_t *w, void *data,PtCallbackInfo_t *cbinfo)
{
   /*
    * Here is the mysterious line !
    * If we remove it, it doesn't work, it crashes
    * on the PtSendEventToWidget call
    */
   char a; //This is a necessary unused variable
   struct{
      PhEvent_t event;
      PhRect_t rect;
      PhPointerEvent_t pevent;
   } new_event;
   
   memset(&new_event.rect,-1,sizeof(new_event.rect));

   new_event.event.processing_flags = 0;
   new_event.event.type = Ph_EV_BUT_PRESS;
   new_event.pevent.click_count = 1;
   new_event.pevent.buttons = Ph_BUTTON_SELECT;
   new_event.event.num_rects = 1;

   printf("%s %d\n",__FILE__,__LINE__);
   PtSendEventToWidget(button1,(PhEvent_t *) &new_event);
   printf("%s %d\n",__FILE__,__LINE__);
}



In the code above, if we remove the declaration of the unused variable a, then we have a crash when PtSendEventToWidget is called.

Thanks for your help
VincentOx
New Member
 
Posts: 4
Joined: Tue May 05, 2009 9:07 am

RE: PtSendEventToWidget memory violation

Postby micro » Tue May 05, 2009 10:27 am

Just some ideas:
Does ist also crash if the printf-lines are removed?
button1 is a global variable?

just for testing, try

struct __attribute__ ((packed)) {
PhEv.....
...
...
} new_event;

I do not think it will change something, but just to be on the save side ^^
We had some trouble with structs, but we had communication between different systems, where one had packed structures in the beginning and second had not... Should not be the problem in here, but giving it a shot is worth.
And since "The widget expects the event to be followed immediately by the associated set of rectangles and event data. See the example below.", you maybe will be ok with having things packed.

Also try new_event.event.data_len = sizeof( PhPointerEvent_t );
micro
Senior Member
 
Posts: 458
Joined: Thu Jul 22, 2004 8:41 pm

RE: PtSendEventToWidget memory violation

Postby VincentOx » Tue May 05, 2009 12:22 pm

Hi,

Yes I tried to remove the printf-line but it still crashes.
I also tried the struct __attribute__ ((packed)) { structure and it didn't make any difference, but as you said it's worth trying it.

However button1 is a global variable. Does it make a difference ?

Thanks for your help
VincentOx
New Member
 
Posts: 4
Joined: Tue May 05, 2009 9:07 am


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests