NicTheQuick wrote:The compiler can not detect runtime errors. GetGadgetItemText() is a runtime function. You could have manipulated the gadget's item count from somewhere else.
+1 - not only by another thread inside the own executable, but also by manipulation from another software running on the system.
PureBasic gives big freedom, but that also includes this freedom to screw up any reference or index. If you have a real problem with this, i would suggest writing your own procedure or macro to replace any gadget access and simply do plenty of range checks in those procedures. If you implement access with range checks as a Macro, you can use a complex macro with safety checks, logging and catching errors during development and once the software is stable enough, you simply replace the macro with a version which just does the access without range checks.
That is actually a pretty useful way to trace processing of data not only to catch errors and bugs, but also to find performance bottlenecks, logical dataflow mistakes and optimize the data/instruction flow during development and still having a fast and slim release binary.
Macros are powerfull for that. Obviously that also means if you screw up your access macros, your software will behave very myteriously
Example Macro i use :
Code: Select all
Macro AddMessage(Message, Level)
SendMessageToPort(Message, 555, Level)
CompilerIf #PB_Compiler_Debugger ; Only enable extended logging in debug mode during development
SendMessageToPort(Str(Level) + "," + #PB_Compiler_Procedure + "(" + #PB_Compiler_Line + ")" + Message, 555)
CompilerEndIf
EndMacro
During development, i usually run from the PB IDE where i have the debugger enabled. So i use that knowledge and the #PB_Compiler_Debugger Flag to have additional code for logging to my custom debugging software.
In your case you would write a macro to replace all gadget functions for your listicongadget and have optional range checks in the macros during development. It is crucial to replace all reference calls to the gadgets with your new macro functions. But once you did that, you have a lot new very useful options to find bugs and optimize your software.