Hi, I am having a problem displaying text in a main console window when its display method is called from a separate thread. im guessing this is a simple problem to fix but I dont know how to solve it! the mis-behavior is sometimes not seeing a message when its printed (Im certain the message text exists because i can print it to standard out and it appears if i click inside the console window) and perhaps crashing the app occasionally (im not sure this mis-behavior is the culprit yet…)
the background: my main app has a Console window that contains a Juce TextEditor as a read/write buffer. The console window has a method ‘void display(String text)’ that the other components in the App can call on to insert text messages into the buffer so users can see them.
now, when other GUI windows such as our Text editor have the focus and then call console->display() it works fine. However, the main use of the console is to print message from a JUCE thread without a gui component that is running Chicken Scheme. The purpose of this thread is to get (lisp) text from our Text Editor, eval it in Chicken Scheme and then print the results to Console. The communication of the JUCE thread with Chicken Scheme seems to be worksing fine and I can always print Scheme’s results to standard out (Terminal.app on MacOSX) wihtout any problems.
However, if the Scheme thread calls console->display() to print the text in the Console window then it MOSTLY works, but sometimes only the first character of the message appears. If I then go and click inside the console window then the text appears. (on rare occasions i think the app gets completly hosed but im not sure if its related to the printing problem yet)
Ive tried making display() call repaint() explicitly but this doesnt seem to fix anything. I am always inserting new messages at the very end of the buffer if that matters. any help appreciated!
–rick taube
this is what my display() function looks like:
void ConsoleWindow::display(String str, ConsoleTheme::ColorType colr) {
const MessageManagerLock mmLock;
console->lock->enter();
setConsoleTextColor(colr);
console->buffer->setCaretPosition(0xFFFFFF); // go to EOB
console->buffer->insertTextAtCursor(str);
console->lock->exit();
}
this is what a call to display() looks like from inside the scheme thread. the printf’s work fine.
{
res = CHICKEN_eval_string_to_string( (char *)expr.toUTF8(),
schemeThread->evalBuffer,
8192);
if ( res==0 ) {
CHICKEN_get_error_message(schemeThread->errorBuffer, 8192);
String text=T(">>> ") + T(String(schemeThread->errorBuffer));
printf("%s\n", text.toUTF8()); // log to terminal
schemeThread->console->display(text, errorColor);
}
else {
printf("Returned: %s\n", schemeThread->evalBuffer); // log to term
schemeThread->console->display(String(schemeThread->evalBuffer), valuesColor);
}
}
