Skip navigation.
Home
The QNX Community Portal

View topic - PtSetResource

PtSetResource

Isn't the name clear?

PtSetResource

Postby nudels » Mon Sep 26, 2011 2:05 pm

Hello,

how can i set the Resource for a Widget (Especially ImageArea)?
when i try to set the Resource with the third parameter that is not a pointer, then i get the Memory fault error.

Code: Select all
int callback2(PtWidget_t* w, void* data, PtCallbackInfo_t* cbInfo)
{
   std::cout << "callback2" << std::endl;
   CircularBuffer* circB = (CircularBuffer*) data;

   PhImage_t img;
   memset(&img,0,sizeof(PhImage_t));

   img.type = Pg_IMAGE_DIRECT_8888;
   img.size.h = 240;
   img.size.w = 640;
   img.alpha = 0;
   img.bpl = 5120;
   img.colors = 0;
   std::cout << "getBuf" << std::endl;
   img.image = circB->getBuf();
   img.flags |= Ph_RELEASE_IMAGE_ALL;
      
   PtSetResource(w, Pt_ARG_IMAGEAREA_IMAGE, &img, 0);

   return Pt_CONTINUE;
}



but even when i create a PhImage_t Pointer and load it with an existing bmp file,
Code: Select all
...
PhImage_t* img = PxLoadImage("/home/write.bmp", NULL);
img->flags |= Ph_RELEASE_IMAGE_ALL;
PtSetResource(w, Pt_ARG_IMAGEAREA_IMAGE, img,0);
...


then it works.
But when i dont load an image and want to change the data, i cant. (like img->size.w = 640;).
then i get the Memory fault error.

Code: Select all

int callback2(PtWidget_t* w, void* data, PtCallbackInfo_t* cbInfo)
{
   std::cout << "callback2" << std::endl;
   CircularBuffer* circB = (CircularBuffer*) data;

   PhImage_t* img;
   memset(img,0,sizeof(PhImage_t));

   img->type = Pg_IMAGE_DIRECT_8888;
   img->size.h = 240;
   img->size.w = 640;
   img->alpha = 0;
   img->bpl = 5120;
   img->colors = 0;
   std::cout << "getBuf" << std::endl;
   img->image = circB->getBuf();
   img->flags |= Ph_RELEASE_IMAGE_ALL;

   PtSetResource(w, Pt_ARG_IMAGEAREA_IMAGE, img, 0);

   return Pt_CONTINUE;
}


now, how can i set the resource without to savind the pic to a bitmap file and then loading it?

i hope somebody can help me :)

with best regards

nudels
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: PtSetResource

Postby maschoen » Wed Sep 28, 2011 3:10 am

You are leaving out a lot of information here. What kind of widget are you setting the IMAGE AREA to?

What does circB->getBuf() return? It better be a memory area that's 5120x240 bytes.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtSetResource

Postby nudels » Wed Sep 28, 2011 12:44 pm

Hey :)

sry for that :)

my Widget is a PtImageArea.
and getBuf() returns a char pointer.

Code: Select all

char* CircularBuffer::getBuf()
{
   // Prüfen ob schon ein Bild abgelegt wurde
   if(_anz>0)
   {
      // Wenn ja, dann Prüfen ob der Zeiger schon über dem Buffer
      // rausgelaufen ist
      if(_posGet < MAXBUFFER)
      {
         // Wenn nein, dann lade das Bild und gib es Zurück
         _pos = _posGet;
         _anz--;
         _posGet++;
         _ptr = _ringBuffer[_pos].buff;
         return (char*)_ptr;
      }
      else
      {
         // Wenn ja, dann setze ihn wieder auf dem Anfang des Buffers,
         // lade das Bild und gib dieses Zurück
         _posGet = 0;
         _pos = _posGet;
         _anz--;
         _posGet++;
         _ptr = _ringBuffer[_pos].buff;
         return (char*)_ptr;
      }
   }
   else {
      return 0;
   }
}



with best regards

nudels
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: PtSetResource

Postby maschoen » Wed Sep 28, 2011 6:18 pm

Yes, well it's a char pointer, but to what? How many bytes? If it's not large enough, it explains your problem.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtSetResource

Postby nudels » Thu Sep 29, 2011 6:09 am

its a pointer to my imagedata.

when i add a callback to my imageArea and init a background worker in this callback, like this:

Code: Select all
/**
 * Callbackfunction 
*/
int activate(PtWidget_t*, void* data ,PtCallbackInfo_t*)
{
   // Erstellen eines Background Workers
   PtWorkProcId_t* id;
   // Definition der Background-Funktion
   PtWorkProcF_t my_work_func;
   // Die Backgroundfunktion hinzufügen und data übergeben
   id = PtAppAddWorkProc(NULL, my_work_func, data);

   return Pt_CONTINUE;
}

// Backgroundworker
int my_work_func(void* data)
{

   daten* _dat = (daten*) data;
   PtArg_t arg[6];
   int n = 0;
   // Lese aus dem CircularBuffer und schreibe das Bild in das Image
   if(NULL != (_dat->_img->image = _dat->_c->getBuf()))
   {
      // Erstelle ein neues ImageArea
      PtSetArg( &arg[n++], Pt_ARG_DIM, &_dat->_img->size, 0 );
      PtSetArg( &arg[n++], Pt_ARG_IMAGEAREA_IMAGE, _dat->_img, 0);

      PtWidget_t* area = PtCreateWidget( PtImageArea, _dat->_w, n, arg );
      if(PtRealizeWidget(area) == -1)
      {
         PtExit(EXIT_FAILURE);
      }
   }

   return Pt_CONTINUE;
}


and daten is a struct.

Code: Select all
struct daten{
   PtWidget_t* _widget;
   CircularBuffer* _circBuf;
   PhImage_t* _img;
};


then it works, but in this code i allways create a new widget, and i think this is a problem, that i have sometimes memory fault / Overrun.

but when i try this code:
Code: Select all
//Callback
int activate(PtWidget_t*, void* data ,PtCallbackInfo_t*)
{
   // Erstellen eines Background Workers
   PtWorkProcId_t* id;
   // Definition der Background-Funktion
   PtWorkProcF_t my_work_func;
   // Die Backgroundfunktion hinzufügen und data übergeben
   id = PtAppAddWorkProc(NULL, my_work_func, data);

   return Pt_CONTINUE;
}


//Baclgroundworker
int my_work_func(void* data)
{

   daten* _dat = (daten*) data;
  // Lese aus dem CircularBuffer und schreibe das Bild in das Image
   if(NULL != (_dat->_img->image = _dat->_c->getBuf()))
   {
      // Setze das Bild als Resource für das ImageArea
      PtSetResource(_dat->_w, Pt_ARG_IMAGEAREA_IMAGE, _dat->_img, 0);
   }

   return Pt_CONTINUE;
}


then it doesn't work :( i only get the first image and then i get memory fault error :/

with best regards

nudels
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: PtSetResource

Postby maschoen » Thu Sep 29, 2011 2:59 pm

Well I've looked over all the code you've posted and I can't see where you allocate the buffer.
I've mentioned twice the possibility that it is the incorrect allocation of size of this buffer that
could be the problem. I don't know what else to say.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron