I have been seeing some unexpected behaviour in one of my applications when a window is closed manually (everything is fine if the window is closed under program control). So I tried to reproduce the problem in a small illustrative app. I failed (so far), but got some equally unexpected behaviour - leading me to wonder if what I am seeing in the real app is just the same problem manifesting differently in a more complex environment.
In the code below, clicking Load opens a graphics region (having checked to to see if one is already open, and closing it if so) i.e. clicking Load repeatedly should repeatedly open and close a single graphics region window. This window should also be closable by clicking at top right. If the graphics window code uses %cc as a closure control, it gives a floating point stack overflow in the closure control callback where it calls clearwin_info@; and if it uses %`cc as a closure control, the closure control callback does not get called at all. Both outcomes are unexpected (by me anyway) 😃 It doesn't matter if the graphics window is closed manually or under program control.
I should say that the original program can have multiple graphics region windows open with associated memory that needs to be freed up, hence the closure control code is rather OTT in this case.
What is going on here?
Andy
program gaga
use callbacks
integer iomain
radio1 = 1
radio2 = 0
ptrgra = 0
iomain = winio@ ('%lw&', cvmain)
iomain = winio@ ('%cn%^bt[Load]&', setgra)
iomain = winio@ ('%ff%nl%fr', 200, 200)
stop
end program gaga
module callbacks
integer cvmain, radio1, radio2, iograp, ptrgra, grawid, hanwin, ctrwin
contains
integer function setgra ()
setgra = 2
if (ptrgra .ne. 0) then
ctrwin = 0
call window_update@ (ctrwin)
end if
grawid = 100
iograp = winio@ ('%gr[user_surface]&', grawid, grawid, ptrgra)
! iograp = winio@ ('%`cc&', auto_clowin)
iograp = winio@ ('%cc&', auto_clowin)
iograp = winio@ ('%hw&', hanwin)
iograp = winio@ ('%cv&', ctrwin)
iograp = winio@ ('%aw', cvmain)
return
end function setgra
integer function auto_clowin ()
integer hanwincur
auto_clowin = 0
hanwincur = clearwin_info@ ('CALL_BACK_WINDOW')
if (hanwincur .eq. hanwin) call clowin (hanwincur)
return
end function auto_clowin
subroutine clowin (hannom)
integer hannom
do
if (hannom .eq. 0) exit ! do-nothing if nothing to do
if (hannom .ne. hanwin) exit ! do-nothing if window handle is unexpected
hanwin = 0
ptrgra = 0
exit ! on normal completion
end do
return
end subroutine clowin
end module callbacks