some fixes, including miscalulation on bounds checking for quickdraw commands, remove some logging from memory error research, refactor chat message count function and add logging on current vs previous message objects to determine phantom beeping, hopefully final test release

This commit is contained in:
camh 2022-02-12 23:23:37 -08:00
parent 0158121fe1
commit 3985d86486
6 changed files with 125 additions and 142 deletions

View File

@ -5,7 +5,7 @@ const createHttpLink = require('apollo-link-http').createHttpLink;
const gql = require('graphql-tag') const gql = require('graphql-tag')
// TEST_MODE can be turned on or off to prevent communications with the Apollo iMessage Server running on your modern Mac // TEST_MODE can be turned on or off to prevent communications with the Apollo iMessage Server running on your modern Mac
const TEST_MODE = false const TEST_MODE = true
const DEBUG = false const DEBUG = false
let lastMessageFromSerialPortTime let lastMessageFromSerialPortTime

Binary file not shown.

Binary file not shown.

View File

@ -25,7 +25,7 @@
// #define MAC_APP_DEBUGGING // #define MAC_APP_DEBUGGING
// #define PROFILING 1 // #define PROFILING 1
#define DEBUG_FUNCTION_CALLS // #define DEBUG_FUNCTION_CALLS
#ifdef PROFILING #ifdef PROFILING
OSErr writeSerialPortProfile(const char* str) OSErr writeSerialPortProfile(const char* str)
@ -182,7 +182,6 @@ void EventLoop(struct nk_context *ctx)
int lastMouseVPos = 0; int lastMouseVPos = 0;
int lastUpdatedTickCountMessagesInChat = 0; int lastUpdatedTickCountMessagesInChat = 0;
int lastUpdatedTickCountChatCounts = 0; int lastUpdatedTickCountChatCounts = 0;
Boolean gotNewMessages = false;
do { do {
@ -198,17 +197,10 @@ void EventLoop(struct nk_context *ctx)
ShowCursor(); ShowCursor();
} }
gotNewMessages = false;
// check for new stuff every 10 sec? // check for new stuff every 10 sec?
// note! this is used by some of the functionality in our nuklear_app to trigger // note! this is used by some of the functionality in our nuklear_app to trigger
// new chat lookups // new chat lookups
if (TickCount() - lastUpdatedTickCountMessagesInChat > 600) { if (TickCount() - lastUpdatedTickCountMessagesInChat > 300) {
gotNewMessages = true;
// writeSerialPortDebug(boutRefNum, "update by tick count");
lastUpdatedTickCountMessagesInChat = TickCount();
if (strcmp(activeChat, "no active chat")) { if (strcmp(activeChat, "no active chat")) {
@ -218,8 +210,8 @@ void EventLoop(struct nk_context *ctx)
} }
// this should be out of sync with the counter above it so that we dont end up making // this should be out of sync with the counter above it so that we dont end up making
// two coprocessor calls on one event loop iteration // two coprocessor calls on one event loop iteratio
if (!gotNewMessages && TickCount() - lastUpdatedTickCountChatCounts > 300) { if (TickCount() - lastUpdatedTickCountChatCounts > 600) {
// writeSerialPortDebug(boutRefNum, "update by tick count"); // writeSerialPortDebug(boutRefNum, "update by tick count");
lastUpdatedTickCountChatCounts = TickCount(); lastUpdatedTickCountChatCounts = TickCount();
@ -319,18 +311,6 @@ void EventLoop(struct nk_context *ctx)
// only re-render if there is an event, prevents screen flickering, speeds up app // only re-render if there is an event, prevents screen flickering, speeds up app
if (beganInput || firstOrMouseMove || forceRedraw) { if (beganInput || firstOrMouseMove || forceRedraw) {
if (beganInput) {
writeSerialPortDebug(boutRefNum, "beganInput");
}
if (beganInput) {
writeSerialPortDebug(boutRefNum, "beganInput");
}
if (forceRedraw) {
writeSerialPortDebug(boutRefNum, "forceRedraw");
}
#ifdef PROFILING #ifdef PROFILING
PROFILE_START("nk_input_end"); PROFILE_START("nk_input_end");
#endif #endif

View File

@ -181,14 +181,16 @@ void sendMessage() {
memset(&box_input_buffer, '\0', 2048); memset(&box_input_buffer, '\0', 2048);
box_input_len = 0; box_input_len = 0;
refreshNuklearApp(1);
// this was an attempt to get the text in the textbox to go away... doesn't really work for a few more redraws
// so actually just makes things slower:
// refreshNuklearApp(1);
callFunctionOnCoprocessor("sendMessage", output, jsFunctionResponse); callFunctionOnCoprocessor("sendMessage", output, jsFunctionResponse);
getMessagesFromjsFunctionResponse(); getMessagesFromjsFunctionResponse();
forceRedraw = 2; forceRedraw = 3;
firstOrMouseMove = true;
return; return;
} }
@ -205,9 +207,10 @@ void getChats() {
callFunctionOnCoprocessor("getChats", "", jsFunctionResponse); callFunctionOnCoprocessor("getChats", "", jsFunctionResponse);
char * token = (char *)strtokm(jsFunctionResponse, ","); char *token = (char *)strtokm(jsFunctionResponse, ",");
// loop through the string to extract all other tokens
while (token != NULL) { while (token != NULL) {
writeSerialPortDebug(boutRefNum, token); writeSerialPortDebug(boutRefNum, token);
sprintf(chatFriendlyNames[chatFriendlyNamesCounter++], "%s", token); sprintf(chatFriendlyNames[chatFriendlyNamesCounter++], "%s", token);
token = (char *)strtokm(NULL, ","); token = (char *)strtokm(NULL, ",");
@ -238,7 +241,7 @@ void sendIPAddressToCoprocessor() {
// set up function to get messages in current chat // set up function to get messages in current chat
// limit to recent messages // limit to recent messages
// figure out pagination?? button on the top that says "get previous chats"? // figure out pagination?? button on the top that says "get previous chats"?, TODO
void getMessages(char *thread, int page) { void getMessages(char *thread, int page) {
#ifdef DEBUG_FUNCTION_CALLS #ifdef DEBUG_FUNCTION_CALLS
@ -284,123 +287,113 @@ void getChatCounts() {
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse); writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
#endif #endif
if (strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) { // bail out if the responses ARE equal
if (!strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING writeSerialPortDebug(boutRefNum, "no need to update current chat count");
writeSerialPortDebug(boutRefNum, "update current chat count"); return;
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse); }
//#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count");
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
writeSerialPortDebug(boutRefNum, previousChatCountFunctionResponse);
//#endif
SysBeep(1);
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
int chatCount = 0;
char *(*chats[16])[64];
chatCount = strsplit(tempChatCountFunctionResponse, (char **)chats, ",");
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "DUMMY DELETE: update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif
}
// loop through the string to extract all other tokens
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif #endif
SysBeep(1); // chats[chatLoopCounter] should be in format NAME:::COUNT
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse); strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
int chatCount = 0; int results = 0;
char *(*chats[16])[64]; char *(*chatUpdate[2])[64];
chatCount = strsplit(tempChatCountFunctionResponse, (char **)chats, ","); results = strsplit((char *)chats[chatLoopCounter], (char **)chatUpdate, ":::");
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) { if (results != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING #ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "DUMMY DELETE: update current chat count loop"); char x[255];
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]); sprintf(x, "ERROR: chat update mismatch splitting on ':::', expected 2 results, got: %d: %s -- bailing out", results, chats[chatLoopCounter]);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < results; errorResultCounter++) {
writeSerialPortDebug(boutRefNum, chatUpdate[errorResultCounter]);
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, results, chatUpdate[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif #endif
continue;
} }
// loop through the string to extract all other tokens short count = atoi((char *)chatUpdate[1]);
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING #ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count loop"); char x[255];
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]); sprintf(x, "name: %s, countString: %s, count: %d", chatUpdate[0], chatUpdate[1], count);
#endif writeSerialPortDebug(boutRefNum, x);
#endif
// chats[chatLoopCounter] should be in format NAME:::COUNT for (int i = 0; i < chatFriendlyNamesCounter; i++) {
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse); if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
int results = 0;
char *(*chatUpdate[2])[64];
results = strsplit((char *)chats[chatLoopCounter], (char **)chatUpdate, ":::"); char chatName[64];
sprintf(chatName, "%.63s", chatFriendlyNames[i]);
if (results != 2) { int updateResults = 0;
char *(*updatePieces[2])[64];
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING updateResults = strsplit(chatName, (char **)updatePieces, " new) ");
char x[255];
sprintf(x, "ERROR: chat update mismatch splitting on ':::', expected 2 results, got: %d: %s -- bailing out", results, chats[chatLoopCounter]);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < results; errorResultCounter++) { if (updateResults != 2) {
writeSerialPortDebug(boutRefNum, chatUpdate[errorResultCounter]);
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, results, chatUpdate[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
short count = atoi((char *)chatUpdate[1]);
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "name: %s, countString: %s, count: %d", chatUpdate[0], chatUpdate[1], count);
writeSerialPortDebug(boutRefNum, x);
#endif
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
char chatName[64];
sprintf(chatName, "%.63s", chatFriendlyNames[i]);
int updateResults = 0;
char *(*updatePieces[2])[64];
updateResults = strsplit(chatName, (char **)updatePieces, " new) ");
if (updateResults != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "ERROR: individual chat update mismatch splitting on ' new) ', expected 2 results, got: %d: %s -- bailing out", updateResults, chatName);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < updateResults; errorResultCounter++) {
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, updateResults, updatePieces[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
if (prefix((char *)updatePieces[1], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match1");
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
if (count == 0 || !strcmp(activeChat, (char *)chatUpdate[0])) {
sprintf(chatFriendlyNames[i], "%.63s", (char *)chatUpdate[0]);
} else {
sprintf(chatFriendlyNames[i], "(%d new) %.63s", count, (char *)chatUpdate[0]);
}
break;
}
} else if (prefix(chatFriendlyNames[i], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING #ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match2"); char x[255];
sprintf(x, "ERROR: individual chat update mismatch splitting on ' new) ', expected 2 results, got: %d: %s -- bailing out", updateResults, chatName);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < updateResults; errorResultCounter++) {
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, updateResults, updatePieces[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
if (prefix((char *)updatePieces[1], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match1");
writeSerialPortDebug(boutRefNum, chatUpdate[0]); writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif #endif
@ -413,16 +406,28 @@ void getChatCounts() {
} }
break; break;
} }
} else if (prefix(chatFriendlyNames[i], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match2");
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
if (count == 0 || !strcmp(activeChat, (char *)chatUpdate[0])) {
sprintf(chatFriendlyNames[i], "%.63s", (char *)chatUpdate[0]);
} else {
sprintf(chatFriendlyNames[i], "(%d new) %.63s", count, (char *)chatUpdate[0]);
}
break;
} }
} }
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
forceRedraw = 3;
} else {
writeSerialPortDebug(boutRefNum, "no need to update current chat count");
} }
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
forceRedraw = 3;
return; return;
} }
@ -446,9 +451,6 @@ void getHasNewMessagesInChat(char *thread) {
writeSerialPortDebug(boutRefNum, "update current chat"); writeSerialPortDebug(boutRefNum, "update current chat");
SysBeep(1); SysBeep(1);
getMessages(thread, 0); getMessages(thread, 0);
// force redraw
forceRedraw = 3;
} else { } else {
writeSerialPortDebug(boutRefNum, "do not update current chat"); writeSerialPortDebug(boutRefNum, "do not update current chat");

View File

@ -451,16 +451,16 @@ NK_API NkQuickDrawFont* nk_quickdraw_font_create_from_file() {
} }
// used for bounds checking // used for bounds checking
int mostLeft = 1; int mostLeft = WINDOW_WIDTH;
int mostBottom = 1; int mostBottom = 1;
int mostTop = WINDOW_HEIGHT; int mostTop = WINDOW_HEIGHT;
int mostRight = WINDOW_WIDTH; int mostRight = 1;
void updateBounds(int top, int bottom, int left, int right) { void updateBounds(int top, int bottom, int left, int right) {
#ifdef DEBUG_FUNCTION_CALLS // #ifdef DEBUG_FUNCTION_CALLS
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: updateBounds"); writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: updateBounds");
#endif // #endif
if (left < mostLeft) { if (left < mostLeft) {
@ -481,6 +481,7 @@ void updateBounds(int top, int bottom, int left, int right) {
mostBottom = bottom; mostBottom = bottom;
} }
writeSerialPortDebug(boutRefNum, "END OF DEBUG_FUNCTION_CALLS: updateBounds");
} }
#ifdef COMMAND_CACHING #ifdef COMMAND_CACHING
@ -1181,10 +1182,10 @@ NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) {
CopyBits(&gMainOffScreen.bits->portBits, &window->portBits, &quickDrawRectangle, &quickDrawRectangle, srcCopy, 0L); CopyBits(&gMainOffScreen.bits->portBits, &window->portBits, &quickDrawRectangle, &quickDrawRectangle, srcCopy, 0L);
mostLeft = 1; mostLeft = WINDOW_WIDTH;
mostBottom = 1; mostBottom = 1;
mostTop = WINDOW_HEIGHT; mostTop = WINDOW_HEIGHT;
mostRight = WINDOW_WIDTH; mostRight = 1;
#ifdef PROFILING #ifdef PROFILING
PROFILE_END("copy bits"); PROFILE_END("copy bits");