11-02-2022 09:28 AM - edited 11-02-2022 09:55 AM
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.-
11-05-2022 05:46 AM
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?
11-10-2022 08:07 AM
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.
11-10-2022 08:48 AM
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.
11-10-2022 09:01 AM
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);
}