Strange behaviour on re-executing an sgl program

11 views
Skip to first unread message

Hendrik Boom

unread,
Aug 16, 2020, 9:32:27 AM8/16/20
to Racket Users
I hauled the sgl-hello-world program (attached below) into drrracket, version 7.6, english by PLT.

I click on 'run'I click on 'run'.
It creates a small window containing a small white square.

I click on 'run' again.
It deetes that window, and creates another small window
containing a small white square.


I click on 'run' again.
It deetes that window, and creates another small window
containing a small white square.

I click on 'run' again.
It deetes that window, and creates another small window
containing a small white square.

etc.

After about 35 runs, the new small window instead contains a large white
square filling the entire window.

Evidently, something happens after multiple runs. Perhaps spme resource
is exhausted Perhaps it's random and might happen after a hundred runs
another time? I don't know. But I'm having similarly erratic behaviour
in a far more complicated program, and this is the simplest version of
erraticity I've found so far.

This code was found on the Racket users mailing list archives.

-- hendrik

--------------
#lang racket/gui

; This code from
https://groups.google.com/forum/#!topic/racket-users/-84bgybC3C0
; -- hendrik

(require (lib "gl.ss" "sgl")
(lib "gl-vectors.ss" "sgl")
)


(define (resize w h)
(glViewport 0 0 w h)
#t
)

(define (draw-opengl)
(glClearColor 0.0 0.0 0.0 0.0)
(glClear GL_COLOR_BUFFER_BIT)
(glColor3d 1.0 1.0 1.0)

(glMatrixMode GL_PROJECTION)
(glLoadIdentity)
(glOrtho 0.0 1.0 0.0 1.0 -1.0 1.0)
(glMatrixMode GL_MODELVIEW)
(glLoadIdentity)

(glBegin GL_QUADS)
(glVertex3d 0.25 0.25 0.0)
(glVertex3d 0.75 0.25 0.0)
(glVertex3d 0.75 0.75 0.0)
(glVertex3d 0.25 0.75 0.0)
(glEnd)
)


(define my-canvas%
(class* canvas% ()
(inherit with-gl-context swap-gl-buffers)

(define/override (on-paint)
(with-gl-context
(lambda ()
(draw-opengl)
(swap-gl-buffers)
)
)
)

(define/override (on-size width height)
(with-gl-context
(lambda ()
(resize width height)
)
)
)

(super-instantiate () (style '(gl)))
)
)

(define win (new frame% (label "OpenGl Test") (min-width 200)
(min-height 200)))
(define gl (new my-canvas% (parent win)))

(send win show #t)



; It should be pretty easy to tweak it.

; Hope this helps,
; Laurent


; - show quoted text -

; - show quoted text -
; _________________________________________________
; For list-related administrative tasks:
; http://lists.racket-lang.org/listinfo/users


Hendrik Boom

unread,
Aug 16, 2020, 10:26:13 AM8/16/20
to Racket Users
I've done more experimenting.


It now looks as if some resource is leaking away that
* is not recovered when one run is cancelled, drracket closes the window, and another run is started, but
* is recovered when I close the window before starting another run.


Experimental results:

If I run my more complicated program (I'll call it streets) it fails the second time I run it.
If I run sgl-hello-world.rkt (which I'll call 'hello' for short) after streets has failed, it fails immediately by producing the large white square.
If I run streets once, and repeatedly run sgl-hello-world.rkt after it, it fails after only about 11 runs, producing the large white square.

When starting straightway with hello, and running it repeatedly, oce the large white square arrives, it is no longer possible to dismiss the small window by clicking on its 'x' cose button in the window frame. But doing another 'run' still does clese the window, and, of coures, creates another with the large white square. And closing drracket still closes all the windows (except, of course, the uxterm from which I started drracket)

If I run streets and manually close its graphics window ny clicking on the 'x' in the window frame before I click 'run' again, it works properly, repeatedly (I tried 7 times). But if after that I fail to close the window, it fails when I press 'run'.

Likewise, if I run hello repeatedly, closing its graphics window explicitly each time, it survives at least a hundred reruns.


-- hendrik
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20200816133219.ln7ameblw7pvpnxo%40topoi.pooq.com.
Reply all
Reply to author
Forward
0 new messages