Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on get-gl-context inside gui-lib/mred/private/mrcanvas.rkt #347

Open
evilactually opened this issue Feb 2, 2025 · 0 comments
Open

Comments

@evilactually
Copy link

This minimum OpenGL example causes a crash on Linux, Ubuntu and Gentoo:

#lang racket/base

(require racket/gui
         sgl)

(define (draw-triangle)
  (gl-viewport 0 0 500 500)
  (gl-begin 'triangles)
  (gl-color 1 0 0)
  (gl-vertex 0 0 0)
  (gl-vertex 0.75 0 0)
  (gl-vertex 0.75 0.75 0)
  (gl-end))

(define my-canvas%
  (class* canvas% ()
    (inherit with-gl-context swap-gl-buffers)
    (define/override (on-paint)
      (with-gl-context (lambda () ;; <- CRASH
                         (draw-triangle)
                         (swap-gl-buffers))))
    (super-instantiate () (style '(gl)))))

(define frame (new frame%
                 [label "OpenGL"]
                 [min-width 500]
                 [min-height 500]))

(define canvas (new my-canvas%
                    [parent frame]))

(send frame show #t)

Running directly from DrRacket produces no useful output, but if I compile it and run it I get a stack trace:

invalid memory reference.  Some debugging context lost
 context...:
  .../private/arrow-higher-order.rkt:379:33
  .../private/mrcanvas.rkt:128:4: with-gl-context method in canvas%
  .../Sources/crash.rkt:18:4: on-paint method in my-canvas%
  .../private/more-scheme.rkt:148:2: call-with-break-parameterization
  .../unsafe/atomic.rkt:73:13
  .../common/canvas-mixin.rkt:144:4: do-on-paint method in canvas-mixin
  .../common/queue.rkt:436:6
  .../common/queue.rkt:487:32
  .../common/queue.rkt:639:3
internal error: attempt to deschedule the current thread in atomic mode
 context...:
  .../common/queue.rkt:639:3

I went in and modified mrcanvas.rkt to see where the error is coming from. It crashes when binding the let statement during the call to the get-gl-context method.

(define/public (with-gl-context
                	thunk
                	#:fail [fail (lambda ()
                               	(error (who->name '(method canvas% with-gl-context))
                                      	"no gl context available"))])
  	(displayln "with-gl-context")
  	(displayln (format "(send wx get-dc):~s" (send wx get-dc)))
  	(displayln (format "(send (send wx get-dc) get-gl-context):~s" (send (send wx get-dc) get-gl-context))) ; <- CRASH
;;   	(let ([ctx (send (send wx get-dc) get-gl-context)])
;;     	(if ctx
;;         	(displayln "calling thunk")
;;         	;(send ctx call-as-current thunk)
;;         	(fail)))

  	)

This produces the output:

(send wx get-dc):#(struct:wrapper-object:dc% ...)
invalid memory reference.  Some debugging context lost
 context...:
  .../private/arrow-higher-order.rkt:379:33
  .../private/mrcanvas.rkt:128:4: with-gl-context method in canvas%
  .../Sources/crash.rkt:18:4: on-paint method in my-canvas%
  .../private/more-scheme.rkt:148:2: call-with-break-parameterization
  .../unsafe/atomic.rkt:73:13
  .../common/canvas-mixin.rkt:144:4: do-on-paint method in canvas-mixin
  .../common/queue.rkt:436:6
  .../common/queue.rkt:487:32
  .../common/queue.rkt:639:3
internal error: attempt to deschedule the current thread in atomic mode
 context...:
  .../common/queue.rkt:639:3

Strangely enough, the program does not crash under Ubuntu when I run it as root. I wonder if it's some kind of X or Wayland permission issue, but why would it affect Racket specifically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant