LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

General Protection Fault when configuring ATTR_FIT_MODE to VAL_SIZE_TO_IMAGE

Hi guys.

 

Due to some needs I migrated the creation of some controls from CVI user interface to my code using NewCtrl function.

 

One of the controls I migrated are Picture Control so I create a function to generate them with some default settings. Something like this:

 

int UI_CreateDefaultPictureButton (int x, int y, CtrlCallbackPtr CtrlCallback, int bitmap)
{
int handle = NewCtrl (PanelHandle, CTRL_PICTURE_COMMAND_BUTTON, NULL, y, x);
InstallCtrlCallback (PanelHandle, handle, CtrlCallback, 0);
SetCtrlAttribute (PanelHandle, handle, ATTR_FIT_MODE, VAL_SIZE_TO_IMAGE);
SetCtrlBitmap (PanelHandle, handle, 0, bitmap);
return handle;
}

 

*a 40x40 bitmap has been already preloaded from a .png file but anyway it don't seems to be related with the issue since it crash before set the bitmap.

 

What I facing a FATAL RUN-TIME ERROR: "The program has caused a 'General Protection' fault at 0x78FD2E2E" when the code is executing the line:

 

SetCtrlAttribute (PanelHandle, handle, ATTR_FIT_MODE, VAL_SIZE_TO_IMAGE);

 

It don't crash the first time I call the function. Depending of the previous code or how I modify my UIR it crash in the first, second or any other instance. It's really weird...

 

In addition it fails only in Debug Mode. In Release it's working fine

 

When the function is not generating the "General Protection" it works perfectly.

 

I'm running Version 20.0.0 (49352). No updates pending in theory.

 

Any ideas of the cause and correction for this issue?

Am I doing something wrong?

 

Thanks.

Pedro.-

0 Kudos
Message 1 of 5
(1,055 Views)

So basically what you do is to tell the control to resize to the internal bitmap before you actually set its bitmap!

 

What's the chance that your CtrlCallback function is actually the culprit as it tries in one of its event handling cases to access the not yet present bitmap data, without trying to verify it first?

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 5
(1,018 Views)

Hi Rolf, thanks for your answer.

 

Yes. basically it's what I'm doing in the function. Creating a Control. Setting an Attribute and loading a bitmap.

I'm not resizing the controls. Just configuring a control attribute. And as i mentioned it's in fact working properly in the first two or three function calls.

 

Anyway of course debugging the issue I confirmed the handle is correctly returned and I moved the attribute change after the bitmap load and I have exactly the same problem.

 

Regards.

0 Kudos
Message 3 of 5
(1,001 Views)

You still haven't answered the question what your CtrlCallback is doing. You install it and it is of course a good possibility that it is actually doing the invalid access somehow.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(994 Views)

The installed callback is just calling a function that is loading and displaying another panel (below code)

Anyway debugging it I created all the controls skipping Callbacks installation and still I'm facing same issue.

 

int CVICALLBACK CallIOPortsPanelOpen (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
IOPortsPanelOpen();
break;
}
return 0;
}

 

void IOPortsPanelOpen(void)
{
if (!PanelIOPorts) PanelIOPorts = LoadPanel (0, "IO_Ports_Panels.uir", IOPORTS);
DisplayPanel (PanelIOPorts);
}

 

 

0 Kudos
Message 5 of 5
(991 Views)