internal error and refreshing problem

BlitzPlus Forums/BlitzPlus Programming/internal error and refreshing problem

allos(Posted 2005) [#1]
triyng to execute the following code, after window closing - in debug mode - I obtain this warning message:
"attempt to release <unknown> object"
the code opens a window with a canvas, and repeatedly grabs canvas to an image drawing something on it at each cycle; but the changes only take place when mouse is moved over the canvas area (not simply positioned 'over' canvas, but 'moving' on it).
This code acts as a model for a more complex piece of software, but I can't figure out the warning message, nor the canvas refreshing behavior.
Some ideas?
; ====================
; === here is the code

win=CreateWindow("win",200,200,300,300,0)
x=ClientWidth(win)
y=ClientHeight(win)
can=CreateCanvas(10,10,200,200,win)
img=CreateImage(200,200)

Repeat

SetBuffer CanvasBuffer(can)
Cls
DrawImage img,0,0
Color Rnd(256),Rnd(256),Rnd(256)
Rect 10,10,100,100
SetBuffer ImageBuffer(img)
GrabImage img,0,0
FlipCanvas(can)

e=WaitEvent()
Select e
Case $803
End
End Select
Forever
; === end of code


CS_TBL(Posted 2005) [#2]
before the 'End' command, add this:
Setbuffer Desktopbuffer()


see if it helps..


allos(Posted 2005) [#3]
thank you CS_TBL, no more warning message
I still can't understand why the canvas does not refresh


CS_TBL(Posted 2005) [#4]
I dunno what your intentions are with this app.. you want the rect to flicker all the time, as in: always update?

This app waits for incoming events.. if nothing happens, nothing happens.


Cold Harbour(Posted 2005) [#5]
Hi, change e=WaitEvent() to e=WaitEvent(5).

See, what's happening is that WaitEvent() waits forever for an event. Moving the mouse over the canvas causes a $203 event - and so your program proceeds. Clicking the mouse will also move the program along as that also causes an event.

WaitEvent(5) waits 5 milliseconds for an event and then proceeds regardless of whether an event happened or not. You can change 5 to whataver you want.


CS_TBL(Posted 2005) [#6]
I wonder what eventually is better.. WaitEvent(time) or a $4001-timer with a normal WaitEvent()..


allos(Posted 2005) [#7]
Ok, thank you
my intention with this app: it is only a model for a more complex software; I need a great deal of lines and other graphic elements to be drawn at each canvas refreshing cycle, and the number of them is increasing in time; so I am looking for a way to avoid continuous redrawing of graphics: I thougth to obtain this by:
1 showing an image
2 drawing some graphics on it
3 grabbing image with added graphics
4 showing the changed image
and so on
maybe this is not the fastes method ...