LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Release version of program crashes

Nick,

 

We're making progress now.  With the crash dump info, I have been able to narrow down where in the code the crash is occurring.

 

Here is the function that is running when the crash occurs:

 

static int ui_block_until_cmd_complete ( struct interface_param * ui_param, char * done_str )
{
    char * return_data /*= NULL*/;
    const int MAX_DELAY = 20000;
    FILE *debugFile;
    
    debugFile = fopen ("d:\\sdpt\\CmtReadTSQData.txt", "a");
    fprintf (debugFile, "In ui_block_until_cmd_complete. Waiting for %s\n", done_str);
    //fclose (debugFile);
    
    for (;;)
    {
        if (CmtReadTSQData (ui_param->queue_handle, &return_data, 1, MAX_DELAY, 0) == 1){
            
            if ( strstr ( return_data, done_str) != NULL){
                //ui_param->ret_func (return_data);
                break;
            } //if
            else if ( strstr ( return_data, "ERROR") != NULL) {
                debug_printf( ui_param->debug, DBGLVL_ERROR,
                    (" ERROR returned: %s\r\n", return_data) );
                ui_param->ret_func (return_data);
                free(return_data);
                return -1;
            }
            
            else if (strstr (return_data, "WARN") != NULL) {
                debug_printf( ui_param->debug, DBGLVL_HIGH,
                    (" WARN returned: %s\r\n", return_data) );
                ui_param->ret_func (return_data);
            }
            
            else if (strstr (return_data, "BUSY") != NULL) {
                debug_printf( ui_param->debug, DBGLVL_HIGH,
                    (" BUSY returned: %s\r\n", return_data) );
                ui_param->ret_func (return_data);
                free (return_data);
                return -1;
            }

            free(return_data);

        } else {
            const char * ret_cmd = "ERROR:  timeout waiting for a return command!\r\n";
            debug_printf( ui_param->debug, DBGLVL_ERROR, (ret_cmd) );
            ui_param->ret_func ((char*) ret_cmd);
            return -1;
        }
        
    } //for (;;)
    
    fprintf (debugFile, "Leaving ui_block_until_cmd_complete.\n");  
    fclose (debugFile);    
    
    return 0;
}

 

A very similar function runs a couple of times before this one is called.  This one actually runs correctly the first time, but apparently fails on the second pass.  The "Leaving ui_block... " message is written to file both times, which would seem to indicate that the CmtReadTSQData function has completed and returned.

 

I confess that I don't understand why the return data pointer is assigned the value of NULL (I just commented out that assignment this morning, but this change didn't have any effect on the crash).  There are a handful of other similar functions that call CmtReadTSQData with the same pointer assignment and these all work (at least in the debugger).

 

 

 

 

0 Kudos
Message 21 of 23
(923 Views)

Just curious - what type of data is being stored in the TSQ?  It's difficult to tell if there is a problem here or not without knowing the type of data stored in the TSQ.

 

NickB

National Instruments

0 Kudos
Message 22 of 23
(921 Views)

  Nick,

 

Here are the code fragments in which the queue is created and written to.  queue_len = 10.  The queue contains command strings (character arrays) that are written to a motion controller via ethernet.

 

 

                    /* setup the queue */

            if (CmtNewTSQ ( queue_len, sizeof (char * ),0,&queue_handle) <0){

                        printf("couldn't create queue\r\n");         

                        return -1;

            }

 

 

 

static int gui_callback (char * buf, int buf_len){

 

            /** @todo not null terminated? */

            //SetCtrlVal ( panelHandle, PANEL_GUI_TEXT_IN, buf) ;

 

            /*

            if ( strstr (buf, "DONE CMD_RUN_") != NULL ){   // this encompasses all CMD_RUN_* commands

                        gui_run = 0;

                        gui_cb_run_done();

            }

            */

 

            //gui_cb_data_to_screen( buf );

 

            char * cmd = malloc( sizeof(char) * (buf_len + 1) );

 

            strcpy (cmd, buf);

 

            if ( CmtWriteTSQData (queue_handle, &cmd, 1,0, NULL) < 1){

                        debug_printf( CLI_DEBUG, DBGLVL_ERROR, ("couldnt queue command, queue full\r\n") );

                        printf("gui:gui_callback: couldnt queue command, queue full\r\n");

                        return -1;

            }

 

}

 

One thing I noticed when delving into the code is that there are 3 separate calls to RunUserInterface().  There are three interfaces, each running in a separate thread.  I hadn't seen this construction before and wondered if there were any reasons not to do things this way.

0 Kudos
Message 23 of 23
(911 Views)