PtBkgd and changing image dynamically

I have a widget on my display that is a PtBkgd widget. I would like to change the image based upon a next or previous button.

I am currently using PxLoadImage to load the image and get the PhImage_t pointer.
I then attempt to set the image into the PtBkgd structure by using

memset( &methods, 0, sizeof( PxMethods_t ) );
methods.px_alloc    = memory_allocate;
methods.px_free     = memory_free;
methods.px_warning  = warning;
methods.px_error    = error;
methods.px_progress = progress;
methods.flags |= PX_LOAD | PX_TRANSPARENT;

ph_img = PxLoadImage( imgfile, &methods ); 
if (ph_img == NULL)
ph_img->flags |= Ph_RELEASE_IMAGE_ALL;
PtSetArg(&bkgd_args[0], Pt_ARGS_BACKGROUND_IMAGE, ph_img, 0);
PtSetResources(AbGetABW(ABN_bg_file), 1, bkgd_args);

But the image is not rendering in the widget. Is there something else I need to do?

It’s been a while since I’ve worked with this widget and loading images etc.

I could be wrong, but I thought the methods structure had to hold the type of images that were acceptable, e.g. JPG, PNG, BMP, etc.

Thank you! I will look into that and report back here.

So, I had to enable allocating the image in shared memory, I was just using the calloc implementation, which was causing the images ot not be displayed. I am adding the image to a background widget using Pt_ARG_BKGD_IMAGE and PtSetResource.

My assumption is that when I call PtUnrealizeWidget(bkgd_widget), that the image memory is released, but I getting frequent segfaults. I am trying to understand if I have a memory leak or if I am running out of shared memory handles (/dev/shmem).


It’s doubtful that you are running out of shared memory handles or shared memory. I’ve never seen either happen and I’ve used Photon a lot. There’s no obvious reason why using non-shared memory would not work but shared memory would. I believe however that shared memory is more efficient with Photon as the image doesn’t need to be message passed to the driver.

You do want to be careful with the image settings as you are correct that the image memory can be auto released if you release the image. Also, I believe that you cannot release the image if you pass it to the background widget as long as you want the background to be displayed.