09-28-2021 12:24 PM
Well, I've coded myself into a corner!
I just finished making a cool little library. The lib allows me to configure table control column cells to behave like a checkbox control, which is currently not supported natively. My lib does a ChainCtrlCallback in order to handle the checkbox image swapping (from checked to unchecked). Give it a column from your table, and the lib makes the necessary cell changes to both new and existing cells. Call the lib Set/Get functions to toggle the image. It all works nicely in a standalone fashion in a simple, small test project.
But now I'm attaching this lib to a bigger project, and now I am seeing General Protection Faults immediately upon RunUserInterface in the application. So it's not debuggable.
I've tried narrowing it down to various likely areas of interest, but I can't find the culprit. I've tried looking at these forum posts: DiscardCtrl, tooltips, toolbar installs. None of these helped me. But! I find that if I remove my ChainCtrlCallback for my lib table, the GPF goes away. I'm not clear why, as I cannot debug this problem.
Any ideas?
Solved! Go to Solution.
09-28-2021 12:37 PM
Not sure if it applies to your situation, but I have seen this kind of errors happening when you try to customize a control which already has a callbackData attached. I'm speaking of heavy customization like the one performed by FileBrowser or similar libraries, which use callbackData parameter to tailor control behavior (I seem to remember that ChainCtrlCallback operates this way)
09-28-2021 02:30 PM
Roberto, add another solution to your pile, sir! I only wish I'd asked you about 3 hours ago, would have saved me a bunch of time.
Sure enough, right in the Help for ChainCtrlCallback:
Once a control's callback is chained, the callback data and the callback function should not be changed using the InstallCtrlCallback function or the ATTR_CALLBACK_DATA and ATTR_CALLBACK_FUNCTION_POINTER attributes.
And indeed, in my host application, I am setting the table callbackData to the currently selected row number. Why? I was trying to be clever and not require a global to look up row selections.
So I replaced all those control attribute Set/Get to panel attributes instead. But alas, still more GPFs! So finally, I removed them all together and finally have crash-free code.
So moral of the story here is be very careful about setting callbackData! Not only is it dangerous if you use ChainCtrlCallback/ChainPanelCallback, it's also pretty obfuscating.
10-01-2021 08:20 AM
It's likely doable but you have to make sure to use the newCallbackData parameter for the ChainCtrlCallback and not try to change the callbackDataPtr through other means. If you want to set something in the callbackDataPtr you have to send a user event to the control so that the callback routine can store that data in the according callbackDataPtr that it receives together with the message.
Obviously things can get tricky when you chain multiple callbacks as you need to make sure to avoid overlapping user event IDs in the different chained callbacks.