620 views
in GUI Development by

Hello , 

Setup description:
Embedded wizard version 8.20
Target CPU: NXPLPC565

we are trying to activate vertical list, by implementing onLoadItem and UpdateArraySourceLogs methodes.
We have declared an array to work with the vertical list:

/* This class implements the interface between the GUI application and the device. */
EW_DEFINE_FIELDS( DataDeviceClass, XObject )
	.
  EW_ARRAY   ( ArraySourceLogs, XString, [1000])
	.
EW_END_OF_FIELDS( DataDeviceClass )

In our GUI application we have declared an array to contain wide-caracter strings and an integer to hold the logs number .
 

unsigned short ushort_sourceArr[10][36] = {'\0'};
int LogsNo = 0;

Then we assigned the first element with "Comm setup" string.
Now, variable 'LogsNo' is equal to 1.

At this point, the debuger show this data:
(XString)ushort_sourceArr[0] = 0x8068DD80 -> "Comm setup".


Then we update the Embedded wizard with logs number (=1) and new string.
 

DataDeviceClass_UpdateLogsNumber(DeviceObject, (XInt32)LogsNo);			//Update EW with logs number        
DataDeviceClass__UpdateArraySourceLogs( DeviceObject, (XString)ushort_sourceArr[0]); 	//Update EW array with new string

Here is 'DataDeviceClass__UpdateArraySourceLogs'  code:
 

/* Wrapper function for the non virtual method : 'Data::DeviceClass.UpdateArraySourceLogs()' */
XInt32 DataDeviceClass__UpdateArraySourceLogs( void* _this, XString aNewValue )
{
  return DataDeviceClass_UpdateArraySourceLogs((DataDeviceClass)_this, aNewValue );
}

/* This method is intended to be called by the device to notify the GUI application 
   about an alternation of its setting or state value. */
XInt32 DataDeviceClass_UpdateArraySourceLogs( DataDeviceClass _this, XString aNewValue )
{
  XInt32 result;

  /* Dummy expressions to avoid the 'C' warning 'unused argument'. */
  EW_UNUSED_ARG( _this );
  EW_UNUSED_ARG( aNewValue );

  result = 0;
  {
    int i;

    for( i =0; i < _this->LogsNumber; i++)
	{
       _this->ArraySourceLogs[i] = EwNewString((XString)aNewValue);   
	}
  }
  return result;
}

The snapshot below shows that the first element of 'ArraySourceLogs' (first was "Data memory" by default ) is now upadate to "Comm setup".

In order to show the vertical list, the program calls 'ScreensEventLogTableContent_OnLoadItem' function:
 

/* This method is called by 'VerticalList' every time the list loads or updates 
   an item. */
void ScreensEventLogTableContent_OnLoadItem( ScreensEventLogTableContent _this, 
  XObject sender )
{
  XInt32 itemNo;
  ScreensEventLogTableItem itemView;

  /* Dummy expressions to avoid the 'C' warning 'unused argument'. */
  EW_UNUSED_ARG( sender );

  itemNo = _this->VerticalList.Item;
  itemView = EwCastObject( _this->VerticalList.View, ScreensEventLogTableItem );

  if ( itemView == 0 )
    return;

  ViewsText_OnSetString( &itemView->Txt_Sourse, EwGetAutoObject( &DataDevice, DataDeviceClass 
  )->ArraySourceLogs[ EwCheckIndex( itemNo, 1000 )]);

  if (( itemNo % 2 ) == 1 )
    ViewsRectangle_OnSetColor( &itemView->ItemBackground, ResLightGray );

  CoreRectView__OnSetBounds( itemView, EwSetRectSize( itemView->Super2.Bounds, EwNewPoint( 
  EwGetRectW( _this->VerticalList.Super2.Bounds ), _this->VerticalList.ItemHeight 
  )));
}

The problem is that when we get to 'ViewsText_OnSetString' we see that the new string (2'nd argument, i.e 'value') is corrupted.


And from this point the program is in its way to get crashed, as shown in snapshot below:

Please help us to understand what we are doing wrong.

Thank you very much!

1 Answer

0 votes
by

Hello,

based on the provided snippets I do not see the root cause of the problem. Nevertheless, can you please check the following:

1.) Can you ensure that the device driver is called from the same thread/task where the entire GUI is running?

2.) Do you have a variable that referes to the autoobject of the device class in order to avoid that it is deleted by the Garbage Collector?

3.) Are you creating the string that is passed to DataDeviceClass__UpdateArraySourceLogs() with EwNewStringAnsi()? Please see also the article Be careful when exchaning strings.

4.) How big is the provided stack?

Best regards,

Manfred.

 

by

Thanks alot for your reply.

Actualy, we replaced the line:

_this->ArraySourceLogs[i] = EwNewString((XString)aNewValue);

 by:

EwRetainString(&_this->ArraySourceLogs[i], EwNewString((XString)aNewValue[i]));

and it works fine (I hope).

by
Did you modify the generated code?

This should be avoided in any case (and it should be never necessary).

Instead the device driver (written in C by yourself) should use EwNewStringAnsi().
by
1. We've modified a line in DataDeviceClass__UpdateArraySourceLogs() function. This function includes our C code.

2. We've converted ANSI strings to wide-caracter strings ourselves, that's why we don't use EwNewStringAnsi() but EwNewString().

Best regards.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...