cancel
Showing results for 
Search instead for 
Did you mean: 

Defining a Line (as a Cursor) in a non-View object crashes when rendered

crazycanuck256
Associate II

There's some sample code here showing how to do an on-screen cursor when editing the content of a TextArea.  I decided it would be easier if I could have a screen independent object that could be associated with any TextAreaWithOneWildcard (which is what I plan to use to display all my editable data fields).

If I define the Line widget I use as a cursor in the TouchGFX Designer it generate code like this in the View's Base class definition:

  touchgfx::Line aCursor;
  touchgfx::PainterARGB2222 aCursorPainter;

then initializes it like so, in the constructor:

aCursor.setPosition(333, 17, 2, 30);
aCursorPainter.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
aCursor.setPainter(aCursorPainter);
aCursor.setStart(0, 0);
aCursor.setEnd(0, 28);
aCursor.setLineWidth(1);
add(aCursor);

I can then associate this with my AttachableCursor class where I define a pointer to a Line widget, which I assign in the constructor of any View that will use it:

attachableCursor.setCursor(&aCursor);

Then when the operator wants to edit a TextArea I associate the cursor to that Text Area (and there are a few methods that support positioning the cursor within the TextArea):

void AttachableCursor::AttachCursorToTextArea(TextArea* textArea, bool visible)

This all works as expected, however, if I try to define the Line widget in code (in my AttachableCursor object) and add it to a View at runtime in the View's constructor (something like this).

add(attachableCursor.getCursor());

There are no complaints until the rendering engine tries to draw the page, then there's an exception in Screen::JSMOC(): "0xC0000005: Access violation reading location 0x0C21183D"; the Call Stack is attached.

I assume I'm missing something about some state information related to the Line Widget, but I'm not sure what that could be.

 

I'm only running this in the simulator at this point, compiling with Visual Studio 2022.

The AttachableCursor code is attached.  You can try it either way depending on whether or not DEFINE_MY_OWN_CURSOR is defined.

0 REPLIES 0