turion / essence-of-live-coding-tutorial

Tutorial for essence-of-live-coding
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

Gloss crashes on mac #3

Open turion opened 4 years ago

turion commented 4 years ago

Apparently on a mac, starting gloss/GLUT crashes:

$ cabal repl
Build profile: -w ghc-8.8.3 -O1
In order, the following will be built (use -v for more details):
 - essence-of-live-coding-tutorial-0.2.0.1 (exe:essence-of-live-coding-tutorial) (first run)
Preprocessing executable 'essence-of-live-coding-tutorial' for essence-of-live-coding-tutorial-0.2.0.1..
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/ninagermanus/repos/essence-of-live-coding-tutorial/.ghci
[1 of 1] Compiling Main             ( Main.hs, interpreted )
Ok, one module loaded.
*Main LiveCoding LiveCoding.GHCi> :livelaunch
*Main LiveCoding LiveCoding.GHCi> 2020-08-14 14:44:29.130 ghc[27231:4244082] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future. Called from (
    0   AppKit                              0x00007fff366e5607 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 378
    1   AppKit                              0x00007fff366e29f7 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1479
    2   AppKit                              0x00007fff366e242a -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
    3   GLUT                                0x00007fff3b699219 -[GLUTWindow _initWithContentRect:styleMask:contentView:] + 84
    4   GLUT                                0x00007fff3b699413 -[GLUTWindow initWithContentRect:pixelFormat:windowID:gameMode:treatAsSingle:] + 353
    5   GLUT                                0x00007fff3b6ab2b8 __glutCreateWindow + 578
    6   GLUT                                0x00007fff3b6ab4ae glutCreateWindow + 239
    7   libHSGLUT-2.7.0.15-3FcmcLd3ijWBc9FSar8jLE-ghc8.8.3.dylib 0x000000010e54057a LcWxZ_info + 114
)
EventResize (600,786)
2020-08-14 14:44:29.251 ghc[27231:4244082] GLUT Fatal Error: internal error: NSInternalInconsistencyException, reason: nextEventMatchingMask should only be called from the Main Thread!

cabal: repl failed for exe:essence-of-live-coding-tutorial from
essence-of-live-coding-tutorial-0.2.0.1.

Found by @pixln

turion commented 4 years ago

@pixln

Could you try the following:

git clone https://github.com/turion/essence-of-live-coding
cd essence-of-live-coding
nix-shell
cd essence-of-live-coding-gloss-example
cabal repl
:livelaunch

This should result in the same error.

Now to hopefully fix it, leave the REPL again and do this:

git checkout dev_forkOS
cabal repl
:livelaunch

This should give a window with 2 balls, and if you click in it, they'll start dancing. Does that work?

Background: https://stackoverflow.com/questions/45197922/glut-fatal-error-when-using-haskell-graphics-gloss

turion commented 4 years ago

We tried additionally to replace further occurrences of forkIO by forkOS, to no avail.

turion commented 4 years ago

@pixln Can you try cabal repl -fglfw?

pixln commented 4 years ago

I tried it, unfortunately, it still leads to the same error message.

➜  essence-of-live-coding git:(dev_forkOS) ✗ nix-shell

[nix-shell:~/repos/essence-of-live-coding]$ cd essence-of-live-coding-gloss-example/

[nix-shell:~/repos/essence-of-live-coding/essence-of-live-coding-gloss-example]$ cabal repl -fglfw
Resolving dependencies...
Build profile: -w ghc-8.8.3 -O1
In order, the following will be built (use -v for more details):
 - essence-of-live-coding-gloss-example-0.2.1 (exe:essence-of-live-coding-gloss-example) (first run)
Preprocessing executable 'essence-of-live-coding-gloss-example' for essence-of-live-coding-gloss-example-0.2.1..
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
cannot satisfy -package essence-of-live-coding-gloss-example
    (use -v for more information)
Loaded GHCi configuration from /Users/ninagermanus/repos/essence-of-live-coding/essence-of-live-coding-gloss-example/.ghci
[1 of 1] Compiling Main             ( app/Main.hs, interpreted )
Ok, one module loaded.
*Main LiveCoding.GHCi Control.Concurrent> :livelaunch
*Main LiveCoding.GHCi Control.Concurrent> 2020-08-21 16:05:33.017 ghc[33735:10551371] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future. Called from (
    0   AppKit                              0x00007fff366e5607 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 378
    1   AppKit                              0x00007fff366e29f7 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1479
    2   AppKit                              0x00007fff366e242a -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
    3   GLUT                                0x00007fff3b699219 -[GLUTWindow _initWithContentRect:styleMask:contentView:] + 84
    4   GLUT                                0x00007fff3b699413 -[GLUTWindow initWithContentRect:pixelFormat:windowID:gameMode:treatAsSingle:] + 353
    5   GLUT                                0x00007fff3b6ab2b8 __glutCreateWindow + 578
    6   GLUT                                0x00007fff3b6ab4ae glutCreateWindow + 239
    7   libHSGLUT-2.7.0.15-3FcmcLd3ijWBc9FSar8jLE-ghc8.8.3.dylib 0x0000000119c8357a LcWxZ_info + 114
)
EventResize (600,792)
2020-08-21 16:05:33.135 ghc[33735:10551371] GLUT Fatal Error: internal error: NSInternalInconsistencyException, reason: nextEventMatchingMask should only be called from the Main Thread!

cabal: repl failed for exe:essence-of-live-coding-gloss-example from
essence-of-live-coding-gloss-example-0.2.1.
turion commented 4 years ago

Hmmm, strange. It seems like the flag didn't have any effect, since you still have "GLUT Fatal Error". But with this flag, GLUT shouldn't even run. I probably got the way these flags work wrong. Can you execute cabal configure --constraint 'essence-of-live-coding-tutorial glfw', and then try cabal repl?

turion commented 4 years ago

I got the command wrong again I think. cabal configure --constraint 'gloss glfw', and then try cabal repl.

turion commented 4 years ago

Adding the constraint gloss +glfw -glut seemed to work for cabal run, but not for cabal repl.

@pixln Can you try cabal repl -- constraint="gloss +glfw -glut"?

turion commented 4 years ago

Also, the flags might have to be upper case, +GLFW -GLUT.

A further option to try is executing cabal install gloss --flags="GLFW -GLUT" first.

turion commented 4 years ago

@pixln I got help from @hvr, who suggests to do:

cabal repl --constraint "gloss source" --constraint "gloss +GLWF -GLUT"

Can you try that?

thielema commented 4 years ago

cabal repl --constraint "gloss source" --constraint "gloss +GLWF -GLUT"

Never knew this syntax. Looks like advanced Cabal usage. So far I use a cabal sandbox, and I guess nix-style local builds plus a cabal.project file would work too.

jegi commented 4 years ago

I guess "GLWF" should be "GLFW"?

jegi commented 4 years ago

Still doesn't work for me:

JG-MacBook-2019:essence-of-live-coding-tutorial jg$ cabal repl --constraint "gloss source" --constraint "gloss +GLFW -GLUT"
Resolving dependencies...
Build profile: -w ghc-8.8.4 -O1
In order, the following will be built (use -v for more details):
 - essence-of-live-coding-tutorial-0.2.3 (exe:essence-of-live-coding-tutorial) (first run)
Preprocessing executable 'essence-of-live-coding-tutorial' for essence-of-live-coding-tutorial-0.2.3..
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
<command line>: dlopen(/Users/jg/.cabal/store/ghc-8.8.4/lib/libHSglss-1.13.1.2-a0b4711e-ghc8.8.4.dylib, 5): Symbol not found: _glsszm1zi13zi1zi2zma0b4711e_GraphicsziGlossziInternalsziInterfaceziBackendziGLUT_glutStateInit_closure
  Referenced from: /Users/jg/.cabal/store/ghc-8.8.4/lib/libHSglss-1.13.1.2-a0b4711e-ghc8.8.4.dylib
  Expected in: flat namespace
 in /Users/jg/.cabal/store/ghc-8.8.4/lib/libHSglss-1.13.1.2-a0b4711e-ghc8.8.4.dylib
cabal: repl failed for exe:essence-of-live-coding-tutorial from
essence-of-live-coding-tutorial-0.2.3.
turion commented 4 years ago

@jegi Sorry this didn't work out for you :/ lesson definitely learned - OpenGL dev environments are hard to set up cross-platform.

jegi commented 4 years ago

No problem. Thanks for the tutorial anyway! I'd like to be able to use something like this for teaching, but the infrastructure doesn't seem to be ready for primetime yet.

turion commented 4 years ago

@jegi Gloss is indeed hard to set up reliably. But essence-of-live-coding itself is completely portable. It's just the backends that work better or worse in different platforms. Is it 2d interactive graphics that you want to teach, or live coding itself? For the latter I think that it works well cross-platform.

turion commented 4 years ago

@jegi For what it's worth, someone else did indeed get the tutorial running on a mac: https://groups.google.com/g/haskell-gloss/c/qHkFOAA2VCY/m/NANJrbsbCAAJ If it's specifically Gloss you're interested in, probably we should ask on the Gloss mailing list.

jegi commented 4 years ago

It was mainly 2D interactive graphics. Livecoding would be a nice touch. But I'd like the materials to be reliably usable by the students on whatever platform they have at home.

turion commented 4 years ago

I see. Well, I believe Gloss's mission was to provide just that.

reubenharry commented 1 year ago

Has anyone had success with this on mac more recently? The live coding runs great out of the box, and gloss works with cabal run, but ghcid quits with

ghcid: Command "cabal repl" exited unexpectedly with ExitFailure 1

(Presumably related to the fact that you can't run gloss in ghci?)

turion commented 1 year ago

(Presumably related to the fact that you can't run gloss in ghci?)

Ah, this is known? Sorry, so far there is no alternative to GHCi in essence-of-live-coding.