OpenQNX :: The QNX Community Portal

May 13, 2008 - 02:30 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 88 unlogged users and 3 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
dunno98
Post subject: Program crash after trying to update label in ptlabel  PostPosted: Apr 05, 2008 - 03:50 PM
New Member


Joined: Apr 05, 2008
Posts: 5

my program crash with the following
Process 626702 (brakeNiNo_NB1207405500342) terminated SIGSEGV code=1 fltno=11 ip=0117e154 mapaddr=00101154. ref=00000014

while a try to change the labe contain.
I am a noob with QNX and this is my first try. Had been look at these error for a long time.. hope some one can help me out here.

Thanks!!

The code are:

Code:


/* Y o u r   D e s c r i p t i o n                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 2.03  */

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <sys/wait.h>

/* Local headers */
#include "ablibs.h"
#include "abimport.h"
#include "proto.h"


#define action1 "Brake - Moderate Braking."
#define action2 "Brake - Fully Engage."
#define action3 "Brake - No Braking"
#define action4 "Accelerator - Disable."
#define action5 "Accelerator - User Control."
#define action6 "System error!!!."

extern int thread_ID;

double d[22];// = {2.0,1.9,1.8,1.7,1.6,1.5,1.4;
double s[22];
char cd[10];
char cs[10];
char note[40];
char uc;
char rm;
int i,p,j;

void* function( void* arg )
{
//printf( "This is thread %d\n", pthread_self() );
      d[0] = 2.0;
        s[0] = 12.0;
       
        d[1] = 1.9;
        s[1] = 11.0;
       
        d[2] = 1.8;
        s[2] = 10.5;
       
        d[3] = 1.7;
        s[3] = 10.0;
       
        d[4] = 1.6;
        s[4] = 9.9;
       
        d[5] = 1.5;
        s[5] = 9.8;
       
        d[6] = 0.8;
        s[6] = 9.7;
       
        d[7] = 0.5;
        s[7] = 8.9;
       
        d[8] = 0.5;
        s[8] = 8.8;
       
        d[9] = 0.5;
        s[9] = 8.8;
       
        d[10] = 0.6;
        s[10] = 8.7;
       
        d[11] = 0.6;;
        s[11] = 8.6;;
       
        d[12] = 0.5;
        s[12] = 8.5;
       
        d[13] = 0.5;
        s[13] = 8.4;
       
        d[14] = 0.4;
        s[14] = 9.2;
       
        d[15] = 0.3;
        s[15] = 8.0;
       
        d[16] = 0.3;
        s[16] = 8.0;
       
        d[17] = 0.3;
        s[17] = 7.0;
       
        d[18] = 0.2;
        s[18] = 6.0;
       
        d[19] = 0.1;
        s[19] = 5.0;
       
        d[20] = 0.0;
        s[20] = 0.0;
       
        d[21] = 0.0;
        s[21] = 0.0;
       

           for (i=0;i<20;i++){
           sprintf(cs, "%2.1f",s[i]);
         sprintf(cd, "%2.1f",d[i]);

             ///PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
             //PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
             if (d[i]>=1.0 && s[i]>=10.0)
                {
                      
                      PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
                    PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
                    PtSetResource( ABW_Ptlbl_N1, Pt_ARG_TEXT_STRING,action1, 0);
                    PtSetResource( ABW_Ptlbl_N2, Pt_ARG_TEXT_STRING,action4, 0);
                }
                else if(d[i]>1.0 && s[i]<10.0)
                {
                      PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
                    PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
                    PtSetResource( ABW_Ptlbl_N1, Pt_ARG_TEXT_STRING,action3, 0);
                    PtSetResource( ABW_Ptlbl_N2, Pt_ARG_TEXT_STRING,action5, 0);
                }     
                else if(d[i]>= 0.5 &&  d[i]<= 1.0)
                {
                      PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
                    PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
                    PtSetResource( ABW_Ptlbl_N1, Pt_ARG_TEXT_STRING,action1, 0);
                    PtSetResource( ABW_Ptlbl_N2, Pt_ARG_TEXT_STRING,action4, 0);
                }
                else if(d[i] > 0.2 && d[i]< 0.5)
                {
                      PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
                    PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
                    PtSetResource( ABW_Ptlbl_N1, Pt_ARG_TEXT_STRING,action2, 0);
                    PtSetResource( ABW_Ptlbl_N2, Pt_ARG_TEXT_STRING,action4, 0);

                }
                else if(d[i] < 0.2)
                {
                      PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
                    PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
                    PtSetResource( ABW_Ptlbl_N1, Pt_ARG_TEXT_STRING,action2, 0);
                    PtSetResource( ABW_Ptlbl_N2, Pt_ARG_TEXT_STRING,action4, 0);
                }
                else
                {
                      PtSetResource( ABW_Ptlbl_Speed, Pt_ARG_TEXT_STRING,cs, 0);
                    PtSetResource( ABW_Ptlbl_Dist, Pt_ARG_TEXT_STRING,cd, 0);
                    PtSetResource( ABW_Ptlbl_N1, Pt_ARG_TEXT_STRING,action6, 0);
                    PtSetResource( ABW_Ptlbl_N2, Pt_ARG_TEXT_STRING,action6, 0);
                }*/
                //delay(20);
                //for ( p=0; p<200000; p++){
                   //for( j=0; j<200; j++){}
                //}
                //sleep(1);
                //for ( p=0; p<1000; p++){}
                /*for (j=0; p<10; p++){
                   cs[i] = NULL;
                   cd[i]=NULL;
           
                }
             //cs="";
             //cd="";
          
           }
           while(1){}
             
return( 0 );
}
int
toggle( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{

   /* eliminate 'unreferenced' warnings */
   widget = widget, apinfo = apinfo, cbinfo = cbinfo;
   
   ////printf("This is a test msg \n");
   //PtSetResource( ABW_PtLabel1, Pt_ARG_TEXT_STRING,"1.00", 0);
   pthread_create(&thread_ID, NULL, &function, NULL);
   //while(1);
   return( Pt_CONTINUE );
   
   }



 
 View user's profile Send private message  
Reply with quote Back to top
maschoen
Post subject: RE: Program crash after trying to update label in ptlabel  PostPosted: Apr 05, 2008 - 06:01 PM
QNX Master


Joined: Jun 25, 2003
Posts: 974

Since the code cannot compile, it would be premature to say what is wrong. Often such errors are based on simple mistakes. Having someone look over your shoulder is a good idea, but if you don't show them the actual code that is failing, it is pointless.
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
dunno98
Post subject:   PostPosted: Apr 05, 2008 - 06:08 PM
New Member


Joined: Apr 05, 2008
Posts: 5

the code can be compile and running on my board
just that after i init the thread the program will crash
i wasn't sure it is ok to use thread in this way.
but it seem a delay in the thread had cause the program to crash
 
 View user's profile Send private message  
Reply with quote Back to top
dunno98
Post subject:   PostPosted: Apr 05, 2008 - 06:50 PM
New Member


Joined: Apr 05, 2008
Posts: 5

I had solve the problem.
It seem that I need to Flush the display using PtFlush as the display does not update itself.

Thanks for viewing
 
 View user's profile Send private message  
Reply with quote Back to top
maschoen
Post subject:   PostPosted: Apr 05, 2008 - 09:13 PM
QNX Master


Joined: Jun 25, 2003
Posts: 974

dunno98 wrote:
the code can be compile and running on my board


Of course it can't. Take a close look. You have an unmatched comment close */ after the last PtSetResource().

In addition, if PtFlush solves the problem, then you are in bigger trouble than you know. There is no predictable reason why this should fix a crash, nor why it's lack should cause one.

You don't seem to know why your loop doesn't make any sense, so you probably need to understand how the widget library works a little better. Just trying to be helpful.
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.