PDA

View Full Version : Trapping the RTE in Ui?



ReneMiner
12-01-2022, 10:45
Right now am in hospital so I can not try, but I look for a solution of the following:
When I use getprop, setprop (win32-api) that allows to attach 4 bytes as a named property to anything that has a windows-handle I.e. hWnd, and my script causes a Runtime-Error, it leads to total crash of thinbasic since the properties are still attached to the automatically destroyed windows objects. Is there a way to either trap the RTE that would allow to use propRemove before the error is shown or could there be an udt-element similar to _Create or _Destroy that would get called in case of an RTE to all existing udts allowing to unbind hooks, attached properties, imagelists, icons etc. Just like


Type tExample
X as Long
Function _Create()
End Function

Function _Destroy()
End Function

Function _RTEexit()
' here either a link to destroy or steps
' that have to be done in case
' of forced exit through Runtime-Error

End function

Thinkeable also as with a callback that is attached to a control that we had a directive - not udt'related as


#InCaseOfRTE
' do what has to be done
#EndCaseOfRTE

ErosOlmi
26-01-2022, 14:48
GPF (General Protection Fault) are that kind of errors trapped by the Windows operating system when a process try to read/write to a memory area not correctly handled.

GPFs can occur for a huge number of possibilities.
Mainly they happen when process read/write a memory area that has not been allocated or has been de-allocated or when a certain amount of memory is allocated but (for some reason) process try to read/write past the end of the allocated area.

That is one of the biggest problem when writing software and using dynamic memory allocation.

thinBasic Core engine keep track of its internal memory but also programmer (when allocating dynamic memory) must put in place solutions to avoid such situations.
And in general Windows API do not check memory to see if it is valid or not. They rely on programmer ability.

For example in this specific case ... instead of calling directly SetPropA or GetPropA you can wrap them in a function that checks if Windows handle is still valid using thinBasic IsWindow and act according.

I will think if I find a way to trap something