Closed zlee-personal closed 3 years ago
I'm not seeing this. For example a foo.rkt
buffer with this:
#lang racket/base
(require racket/gui)
"hi, world"
When I M-x racket-run
, in the *Racket-REPL*
buffer I see:
; on-demand one-time instantiation of racket/gui/base
"hi, world"
foo.rkt>
So can you help me out with more information?
Please paste output of M-x racket-bug-report
here, so I can see versions of Emacs, Racket, racket-mode, etc. you're using.
If my foo.rkt
program shows the problem for you, great, please let me know that. Otherwise, please give me the simplest example .rkt
file you can, that does show the problem.
racket bug report gives:
Your foo.rkt works. I have somewhat isolated the issue: the repl works fine until I try to run the (main) function that uses the big-bang function from 2htdp/universe. After messing around, I also noticed that if I run the program, then press C-c C-c to interrupt the process when it is frozen, it will exit into a racket repl not inside the file. If I run the file again, it will work fine, run the program, and go to a repl inside the file. If I close the repl and try to run it again, I have to repeat the C-c C-c thing for it to work. This only happens on windows also.
Thanks for the additional information!
This may take me awhile to figure out what's going on. Also, I don't have a Windows laptop with me now; I will toward the end of next week.
Maybe I should make a VirtualBox VM for situations like this, and buy a Windows license.
OK I installed VirtualBox, downloaded and installed this free Windows VM from Microsoft, installed Emacs for Windows and Racket for Windows.
I've never used 2htdp/universe
and big-bang
. Can you give me an example program that shows the problem?
Here is a simple program that uses big-bang
:
#lang racket
(require 2htdp/image)
(require 2htdp/universe)
(big-bang 1 ; initial state
[to-draw (lambda (x) ; draws a square of x length over a white background
(underlay/xy (rectangle 100 100 "solid" "white")
50
50
(square x 'solid "red")))]
[on-tick add1] ; adds 1 to the state every tick
[stop-when (lambda (x) (> x 50))]) ; stops when state is over 50
It pretty much passes state between functions and draws something using the to-draw
function every tick. This big-bang
displays a square that gets larger by 1 every tick. When it is finished, (when the stop-when
function returns true), the big-bang
function returns the final state, in this case 51
. What I noticed happening, is that the execution of the program will finish, and the function will return 51. However, no graphics will be displayed. Then, when you run it again, the graphics work. When I was running the program which first caused the issue, it seemed to freeze, because my big-bang
needs input from the user in order to end, so racket-mode thought that my big-bang
was running and it just waited for it to stop.
I can confirm that this is a problem with racket-mode on Windows when racket is first started up. @vityou , your example will work if you start the program again (i.e hit F5) without stopping racket.exe.
The problem is that the program runs fine but any windows don't get displayed, even though they are created. Consider this example, which creates a frame, than shows it:
#lang racket
(require racket/gui)
(define f (new frame% [label "hello"] [width 100] [height 100]))
(send f show #t)
If I hit F5 to start a new racket program, the frame is created, but it will not show up. If I than type (send f show #t)
in the REPL, the frame will show up. If I evaluate the program again (i.e hit F5), the frame will show without the extra REPL step.
This is a problem that existed for a while, but it has never bothered me. Even for complex programs, if racket.exe is started for the first time, I just enter a (send toplevel show #t)
at the REPL to show the window and everything works fine.
@alex-hhh Thanks for joining in.
When racket-mode prints:
; on-demand one-time instantiation of racket/gui/base"
Do you suppose it should also print something like:
; TIP: If your frame% window doesn't appear, try entering (send frame show #t).
@alex-hhh: What do you think? @vityou: Would that have helped you?
p.s I'm at a conference and haven't had time to sit down with Windows, yet, and see if there's anything else I could do.
I think it should print something like "if your window doesn't show up, try running the program again without deleting this buffer". Sending something to the frame wouldn't be possible in some cases if the program is still running as the repl wouldn't accept input.
Any message would be misleading:
(send frame show #t)
fixes the problem, but a frame is not always available. For example, in the 2htdp
there is no toplevel frame exported (as far as I know) so this would not work in that case. I also suspect the problem is that the eventspace for the GUI is not ready yet, and any program that makes use of that eventspace before the window is shown will not be fixed by this workaround.I can spend some time trying to see what the problem is. It might also be worth asking about this on racket-users, as the racket developers will know more about how the GUI is initialized.
Experimenting with this a bit more, I found out that having two show invocations makes it work with racket-mode:
#lang racket
(require racket/gui)
(define f (new frame% [label "hello"] [width 100] [height 100]))
(send f show #t)
(send f show #t)
The original program, with only one "show" invocation, works when racket is started from the command line. That is, saving the code to "example.rkt" and running "racket example.rkt".
@greghendershott , can you confirm that you cannot reproduce this on Linux or OSX? -- this would make it Windows specific.
With no *Racket REPL*
yet created, on macOS 10.11.6 with Racket 6.10 and Emacs 25.1.1 -- the window appears with a single (send f show #t)
.
(In fact it appears in the foreground on top of Emacs' window -- even when Emacs is in full screen mode).
I did finally get a chance to try Windows 10 in Virtual Box.
@alex-hhh I see the same behavior as you (on Windows) regarding the need to show the frame twice.
@vityou when I try your big bang example I see the same behavior as you (on Windows).
As I mentioned before, I don't see this same behavior on macOS.
I'm not sure what to do about this in racket-mode, other than document this?
This seems to be a windows specific issue, indeed. I think it would be worth asking for help on the racket mailing lists.
I have a commit for this; it shows then immediately hides an initial frame on Windows. Although that's a work-around, it seems to fix this satisfactorily in my testing today.
p.s. I'm sorry to be so slow to follow through on this. In recent days I took some time to revisit racket/gui/base
handling on all platforms, as well as to fix some failing tests on Windows. Windows is now part of CI (easier on GitHub Actions than previously on Travis CI) so that should help going forward.
Upon pressing f5, the repl opens, prints "on-demand one-time instantiation of racket/gui/base", and doesn't ever run the program. This only happens with programs which require gui.