A picture says more than 1000 words, therefor a screenshot with notes of improvements and fixes of the IDE (running on Windows 11):
Since last year virus-scanners report the patched runtime (GfaWin23.Ocx) as malicious - a false positive! Consequently, it is no longer possible to release a runtime binary with bug fixes. A new way of fixing bugs had to be introduced. Starting with this update version 2.62 the runtime bugs are fixed on the fly, they are patched when the program is run (F5). For this to happen each new program automatically inserts the following lines:
$Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx
The $Library “UpdateRT” command loads the compiled code with the exported procedure UpdateRuntime. The UpdateRuntime should be the first statement executed, so that the runtime is fixed before the actual program is run. By taking this approach we can continue fixing runtime bugs!
You can inspect the source code in UpdateRT.g32, which is stored in the Include directory.
For older programs these lines have to be added manually, so that they benefit form the fixes as well.
See also: Update 2.6 produces a false positive (virus scanner)
Fixed: the Branch-Optimization compiler bug
This update sets an important step forward by fixing the compiler’s Branch-Optimizing bug. When Branch-Optimizations was set to any other value than zero the program could crash in one particular situation: when a Case or Otherwise statement was directly followed by an Exit command or one of its variants (Exit, Exit For/Do, Exit Proc, etc). The EXE crashed also if ‘Full Optimization for EXE’ was set. Now this problem is fixed, your program can benefit from full branch optimization, it reduces the size of the program by 10% and increases performance.
A couple of new IDE features.
- The editor now shows format lines (toggle with Ctrl+F7) and you can use PeekView to hoover over format lines to see what statements are connected by a format line.
- New projects can be started from a template, ranging from a simple Hello World app to a sophisticated dpi-aware application. The templates can be found in the File | New menu-item.
- AC (auto-complete) comes with many improvements.
- In dark-mode the proc-line color is changed and the auto-complete list box is displayed in dark mode as well.
See Readme262.rtf for more fixes and improvements.
New Commands/Functions in gfawinx.lg32
- PrevInstance helps in starting a program only once.
- DlgCenter centers all GB32 dialog boxes in the main thread on top of their owner (Me).
DlgCenterHook is used to center the dialog boxes in a additional threads.
- WorkWidth & WorkHeight return the real size of the clientarea of a Form with a toolbar and/or statusbar.
- OffsetXY sets the graphical offset using positive values for GB32 graphical commands.
- VStrLen, VStrLenB, and VStrPtr return the length (in character or bytes) and the address of a string in a Variant.
- AutoFreePtr returns a COM object for storage of handles and (memory) pointers that need proper releasing, even when the program halts with a runtime error or Stop/End. The COM object has a Ptr (read/write) property to read and update the resource after the object is created.
See the updated CHM help-file for detailed information about these new features.
Note – gfawinx.lg32 is loaded automatically in new projects. Optionally, this can be disabled in the Extra tab of GFA-BASIC 32 Properties.
The new App_Close event
Probably the most important new feature of this update is the introduction of an application close event: the App_Close event sub. This event sub is automatically called after the program is closed. It provides a way to free global resources that might never be released otherwise. This happens when developing a program and the program stops abruptly with a runtime error. This happens all the time. When a runtime error occurs the IDE shows a message box telling about the error and puts an arrow on the line that caused the error. Maybe you don’t always realize, but after execution stopped no more code is executed and allocated resources won’t be released. For instance:
OpenW 1 ' Create global resources Do Sleep Until Me Is Nothing ' Delete resources: might never be reached!
The releasing of resources also fails when a program ends with the End or Stop statement, no more code is run after these commands. Any API handles, memory pointers, bitmaps, and other global resources are not released and the program is leaking memory. When the program is run again and then stops again in the middle of the execution the leakage accumulates and soon you might experience unexpected errors. Even more, there are situations where the program can’t be run again, because of locked handles (for instance mutex handles). By using App_Close this leaking is over:
OpenW 1 ' Create global resources Do Sleep Until Me Is Nothing Sub App_Close() ' Delete resources: guaranteed to be released! EndSub
Now put the program-lines that free the resources in the App_Close sub and the global resources are guaranteed to be released in all situations.
The AutoFreePtr object
The implementation of App_Close is only possible through the introduction of the AutoFreePtr object. Instead of using the App_Close event sub a resource can also be assigned to an AutoFreePtr, which will call a predefined or custom procedure to free the resource. Because App_Close can only be used for globally stored resources, any local resource can be automatically released by using an AutoFreePtr. For instance, when a procedure temporarily allocates some memory that needs to be freed at the end of procedure:
Proc Something Local pmem As Long, Mem As Object pmem = mAlloc(100) ' alloc some memory ' Allocate an AutoFreePtr object and ' let it call mFree() automatically Set Mem = AutoFreePtr(pmem, AfpMfree) ' use pmem or Mem.Ptr pmem = mShrink(pmem, 50) ' resize memoryblock Mem.Ptr = pmem ' assign new pointer EndProc ' No mFree call necessary!
The AutoFreePtr object provides a Ptr property (Long - Get/Put) to read the assigned pointer or handle and to re-assign a new pointer/handle.
The AutoFreePtr can free several predefined pointer or handle types. By specifying an Afp* constant you can instruct the AutoFreePtr object to invoke that specific release function for you. See the helpfile for more info on which types can be freed automatically.
Instead of specifying a constant to execute a predefined freeing-function, you can set a custom procedure to call when the AutoFreePtr object goes out of scope.
Proc Something2 Local pmem As Long, Mem As Object pmem = mAlloc(100) ' alloc some memory Set Mem = AutoFreePtr(pmem, ProcAddr(FreeMem)) ' use pmem or Mem.Ptr EndProc ' mFree executed in FreeMem() Proc FreeMem(ByVal ptr As Long) ~mFree(ptr) EndProc
Start using App_Close and AutoFreePtr to develop without leaking memory and handles.
Download the new update: GFA-BASIC 32 for Windows: Download
Post a Comment