PtSendEventToWidget memory violation

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:

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

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 );

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