AlexCharlton / Hypergiant

An OpenGL-based game library for CHICKEN Scheme
BSD 2-Clause "Simplified" License
68 stars 5 forks source link

Segmentation Violation #7

Open dleslie opened 9 years ago

dleslie commented 9 years ago

I ran into a segmentation violation while a short way into the tutorial you wrote:

(import chicken scheme)
(use hypergiant)

(define keys (make-bindings
              `((quit ,+key-escape+ press: ,stop))))

(define scene (make-parameter #f))
(define camera (make-parameter #f))

(define board-mesh (rectangle-mesh 1.2 1.2
                                   color: (lambda (_)
                                            '(0.5 0.4 0.2))))

(define (init-board)
  (add-node (scene) color-pipeline-render-pipeline
            mesh: board-mesh
            position: (make-point 0.5 0.5 0)))

(define (init)
  (push-key-bindings keys)
  (scene (make-scene))
  (camera (make-camera #:perspective #:position (scene) 
                       near: 0.001 angle: 35))
  (set-camera-position! (camera) (make-point 0.5 0.5 2))
  (init-board))

(start 800 600 "Go" resizable: #f init: init)

Output:

Error: segmentation violation

    Call history:

    glls-renderable.scm:502: gl-utils-mesh#mesh-n-indices     
    glls-renderable.scm:508: get-arg      
    glls-renderable.scm:486: get-keyword      
    glls-renderable.scm:488: default      
    glls-renderable.scm:508: set-renderable-offset!   
    glls-renderable.scm:53: address->pointer      
    glls-renderable.scm:482: symbol->string   
    glls-renderable.scm:482: string->keyword      
    glls-renderable.scm:516: get-arg      
    glls-renderable.scm:486: get-keyword      
    glls-renderable.scm:515: set-renderable-uniform-value!    
    glls-renderable.scm:57: f32vector?    
    glls-renderable.scm:62: s32vector?    
    glls-renderable.scm:67: u32vector?    
    glls-renderable.scm:72: pointer?      
    glls-renderable.scm:518: loop       <--

I'm using the latest 64-bit MateUbuntu with an AMD A4-5000 APU that has a builtin Radeon HD 8330.

dleslie commented 9 years ago

Chicken 4.9.0.1, and whatever is in fglrx-updates. ;)

dleslie commented 9 years ago

Oh, and versions:

amb ........................................................... version: 2.1.6
amb-extras .................................................... version: 2.1.6
apropos ....................................................... version: 2.1.2
awful ........................................................ version: 0.41.0
awful-server ................................................. version: 0.41.0
awful-sqlite3 ................................................. version: 0.6.0
awful-ssl ....................................................... version: 0.2
base64 ........................................................ version: 3.3.1
bind .......................................................... version: 1.5.2
bitstring ...................................................... version: 1.33
blob-hexadecimal .............................................. version: 1.0.3
blob-set-int .................................................. version: 1.0.3
blob-utils .................................................... version: 1.0.3
check-errors ................................................. version: 1.13.0
chicken-bind .................................................. version: 1.5.2
chicken-doc ................................................... version: 0.4.6
chicken-doc-cmd ............................................... version: 0.4.6
chicken-dump .................................................. version: 0.9.6
chicken-wrap ................................................. version: 1.99.7
condition-utils ............................................... version: 1.1.1
coops .......................................................... version: 1.93
cplusplus-object .............................................. version: 1.5.2
defstruct ....................................................... version: 1.6
easyffi ...................................................... version: 1.99.7
easyffi-base ................................................. version: 1.99.7
fmt ........................................................... version: 0.805
fmt-c ......................................................... version: 0.805
fmt-color ..................................................... version: 0.805
fmt-js ........................................................ version: 0.805
fmt-unicode ................................................... version: 0.805
foreigners .................................................... version: 1.4.1
freetype ........................................................ version: 0.1
gl-math ....................................................... version: 0.7.0
gl-type ....................................................... version: 0.2.1
gl-utils ...................................................... version: 0.6.0
glfw3 ......................................................... version: 0.6.1
glls ......................................................... version: 0.11.0
html-tags ...................................................... version: 0.11
html-utils ..................................................... version: 0.10
http-client-conditions ........................................ version: 1.1.1
http-session .................................................... version: 2.8
hypergiant .................................................... version: 0.3.2
hyperscene .................................................... version: 0.3.0
inline .......................................................... version: 1.9
intarweb ........................................................ version: 1.3
intarweb-conditions ........................................... version: 1.1.1
irc ........................................................... version: 1.9.8
iset ............................................................ version: 1.9
json ............................................................ version: 1.5
linden-scheme ................................................. version: 0.1.4
lookup-table ................................................. version: 1.13.5
lookup-table-synch ........................................... version: 1.13.5
lookup-table-unsafe .......................................... version: 1.13.5
lookup-table-unsafe-synch .................................... version: 1.13.5
lru-cache ..................................................... version: 0.5.3
make ............................................................ version: 1.7
matchable ....................................................... version: 3.3
md5 ........................................................... version: 3.1.0
memcached ....................................................... version: 1.3
memoized-string ............................................... version: 1.2.4
message-digest ................................................ version: 3.1.0
message-digest-basic .......................................... version: 3.1.0
message-digest-bv ............................................. version: 3.1.0
message-digest-int ............................................ version: 3.1.0
message-digest-item ........................................... version: 3.1.0
message-digest-parameters ..................................... version: 3.1.0
message-digest-port ........................................... version: 3.1.0
message-digest-primitive ...................................... version: 3.1.0
message-digest-srfi-4 ......................................... version: 3.1.0
message-digest-support ........................................ version: 3.1.0
message-digest-type ........................................... version: 3.1.0
message-digest-update-item .................................... version: 3.1.0
miscmacros ..................................................... version: 2.96
nanomsg ......................................................... version: 0.2
noise ......................................................... version: 0.1.5
numbers ......................................................... version: 4.1
openal .......................................................... version: 0.8
opengl-glew ................................................... version: 0.9.2
openssl ....................................................... version: 1.6.4
packrat ......................................................... version: 1.4
physfs .......................................................... version: 2.2
protobuf ...................................................... version: 1.1.2
protoc-gen-chicken ............................................ version: 1.1.2
random-mtzig .................................................... version: 3.3
record-variants ............................................... version: 0.5.1
regex ........................................................... version: 1.0
rest-bind ....................................................... version: 0.5
s11n .......................................................... version: 0.9.6
salmonella ...................................................... version: 2.7
salmonella-cmd .................................................. version: 2.7
salmonella-epidemy .............................................. version: 2.7
salmonella-log-merger ........................................... version: 2.7
salmonella-log-parser ........................................... version: 2.7
salmonella-log-viewer ........................................... version: 2.7
sendfile ..................................................... version: 1.7.30
setup-helper .................................................. version: 1.5.5
setup-helper-mod .............................................. version: 1.5.5
sha1 .......................................................... version: 3.1.0
sha2 .......................................................... version: 3.1.0
silex ........................................................... version: 1.4
simple-sha1 ..................................................... version: 0.4
soil .......................................................... version: 1.4.1
spiffy ........................................................ version: 5.3.2
spiffy-cookies .................................................. version: 1.1
spiffy-request-vars ............................................ version: 0.17
sql-de-lite ................................................... version: 0.6.4
sql-de-lite-shell ............................................. version: 0.6.4
sql-null ........................................................ version: 1.1
sqlite3 ....................................................... version: 3.6.1
srfi-4-checks ................................................ version: 1.13.0
srfi-4-comprehensions ........................................... version: 1.4
srfi-4-errors ................................................ version: 1.13.0
srfi-42 ........................................................ version: 1.73
srfi-99 ....................................................... version: 1.4.4
standard-conditions ........................................... version: 1.1.1
string-hexadecimal ............................................ version: 1.2.4
string-utils .................................................. version: 1.2.4
sxml-transforms ............................................... version: 1.4.1
symbol-utils .................................................. version: 1.0.2
synch ......................................................... version: 2.1.2
termbox ....................................................... version: v0.11
test ........................................................ version: 0.9.9.8
to-hex ........................................................ version: 1.2.4
tween ........................................................... version: 1.1
type-checks .................................................. version: 1.13.0
type-errors .................................................. version: 1.13.0
udp ............................................................ version: 1.18
unicode-char-sets ............................................. version: 3.3.9
unicode-utils ................................................. version: 1.2.4
uri-common ...................................................... version: 1.4
uri-generic .................................................... version: 2.41
utf8 .......................................................... version: 3.3.9
utf8-case-map ................................................. version: 3.3.9
utf8-lolevel .................................................. version: 3.3.9
utf8-srfi-13 .................................................. version: 3.3.9
utf8-srfi-14 .................................................. version: 3.3.9
uuid-lib ...................................................... version: 1.4.1
variable-item ................................................. version: 1.3.1
z3 ............................................................. version: 1.44
zmq ........................................................... version: 0.1.4
dleslie commented 9 years ago

Moved to glls

AlexCharlton commented 9 years ago

Unsurprisingly this code Works For Me. That error message is really unhelpful, too. I suspect we'll get a better idea of what's actually going on if you reinstall hypergiant and hyperscene with chicken-install -D debug.

While I doubt this has anything to do with it, can I get your OpenGL version? You should be able to get it with `glxinfo | grep "OpenGL version".

Also can you see if there are any differences between compiling and interpreting that test code. When you compile, don't forget you need to link with GL, i.e. csc -lGL test.scm.

dleslie commented 9 years ago

So I rebuilt hyperscene, hypergiant and glls with -D debug; here's the new call stack for csi:

CHICKEN
(c) 2008-2014, The Chicken Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.9.0.1 (stability/4.9.0) (rev 8b3189b)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
bootstrapped 2014-06-07

#;1> (load "main.scm")
; loading main.scm ...
; loading /usr/local/lib/chicken/7/chicken.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant.import.so ...
; loading /usr/local/lib/chicken/7/foreign.import.so ...
; loading /usr/local/lib/chicken/7/opengl-glew.import.so ...
; loading /usr/local/lib/chicken/7/bind.import.so ...
; loading /usr/local/lib/chicken/7/bind-translator.so ...
; loading /usr/local/lib/chicken/7/silex.so ...
; loading /usr/local/lib/chicken/7/regex.so ...
; loading /usr/local/lib/chicken/7/matchable.so ...
; loading /usr/local/lib/chicken/7/gl-math.import.so ...
; loading /usr/local/lib/chicken/7/srfi-1.import.so ...
; loading /usr/local/lib/chicken/7/extras.import.so ...
; loading /usr/local/lib/chicken/7/lolevel.import.so ...
; loading /usr/local/lib/chicken/7/srfi-4.import.so ...
; loading /usr/local/lib/chicken/7/gl-utils.import.so ...
; loading /usr/local/lib/chicken/7/gl-utils-core.import.so ...
; loading /usr/local/lib/chicken/7/matchable.import.so ...
; loading /usr/local/lib/chicken/7/miscmacros.import.so ...
; loading /usr/local/lib/chicken/7/gl-utils-ply.import.so ...
; loading /usr/local/lib/chicken/7/gl-utils-bytevector.import.so ...
; loading /usr/local/lib/chicken/7/gl-utils-mesh.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99-records.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99-records-procedural.import.so ...
; loading /usr/local/lib/chicken/7/srfi-69.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99-primitives.import.so ...
; loading /usr/local/lib/chicken/7/data-structures.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99-records-inspection.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99-records-syntactic.import.so ...
; loading /usr/local/lib/chicken/7/srfi-99-variants.import.so ...
; loading /usr/local/lib/chicken/7/z3.import.so ...
; loading /usr/local/lib/chicken/7/ports.import.so ...
; loading /usr/local/lib/chicken/7/posix.import.so ...
; loading /usr/local/lib/chicken/7/srfi-42.import.so ...
; loading /usr/local/lib/chicken/7/srfi-13.import.so ...
; loading /usr/local/lib/chicken/7/files.import.so ...
; loading /usr/local/lib/chicken/7/gl-type.import.so ...
; loading /usr/local/lib/chicken/7/freetype.import.so ...
; loading /usr/local/lib/chicken/7/foreigners.import.so ...
; loading /usr/local/lib/chicken/7/srfi-14.import.so ...
; loading /usr/local/lib/chicken/7/noise.import.so ...
; loading /usr/local/lib/chicken/7/glls.import.so ...
; loading /usr/local/lib/chicken/7/glls-compiler.import.so ...
; loading /usr/local/lib/chicken/7/fmt.import.so ...
; loading /usr/local/lib/chicken/7/fmt-c.import.so ...
; loading /usr/local/lib/chicken/7/irregex.import.so ...
; loading /usr/local/lib/chicken/7/glls-compiler.so ...
; loading /usr/local/lib/chicken/7/fmt.so ...
; loading /usr/local/lib/chicken/7/fmt-c.so ...
; loading /usr/local/lib/chicken/7/soil.import.so ...
; loading /usr/local/lib/chicken/7/hyperscene.import.so ...
; loading /usr/local/lib/chicken/7/glls-render.import.so ...
; loading /usr/local/lib/chicken/7/glls-renderable.import.so ...
; loading /usr/local/lib/chicken/7/glls-renderable.so ...
; loading /usr/local/lib/chicken/7/glls.so ...
; loading /usr/local/lib/chicken/7/opengl-glew.so ...
; loading /usr/local/lib/chicken/7/bind.so ...
; loading /usr/local/lib/chicken/7/gl-utils-core.so ...
; loading /usr/local/lib/chicken/7/gl-utils-mesh.so ...
; loading /usr/local/lib/chicken/7/gl-utils-bytevector.so ...
; loading /usr/local/lib/chicken/7/srfi-99.so ...
; loading /usr/local/lib/chicken/7/gl-math.so ...
; loading /usr/local/lib/chicken/7/hypergiant-render-pipeline.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant-window.import.so ...
; loading /usr/local/lib/chicken/7/glfw3.import.so ...
; loading /usr/local/lib/chicken/7/glfw3-bindings.import.so ...
; loading /usr/local/lib/chicken/7/srfi-18.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant-shaders.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant-sprites.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant-particles.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant-geometry.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant-models.import.so ...
; loading /usr/local/lib/chicken/7/bitstring.import.so ...
; loading /usr/local/lib/chicken/7/random-mtzig.import.so ...
; loading /usr/local/lib/chicken/7/hypergiant.so ...
; loading /usr/local/lib/chicken/7/gl-utils.so ...
; loading /usr/local/lib/chicken/7/gl-utils-ply.so ...
; loading /usr/local/lib/chicken/7/z3.so ...
; loading /usr/local/lib/chicken/7/srfi-42.so ...
; loading /usr/local/lib/chicken/7/gl-type.so ...
; loading /usr/local/lib/chicken/7/freetype.so ...
; loading /usr/local/lib/chicken/7/noise.so ...
; loading /usr/local/lib/chicken/7/soil.so ...
; loading /usr/local/lib/chicken/7/hyperscene.so ...
; loading /usr/local/lib/chicken/7/glls-render.so ...
; loading /usr/local/lib/chicken/7/hypergiant-render-pipeline.so ...
; loading /usr/local/lib/chicken/7/hypergiant-window.so ...
; loading /usr/local/lib/chicken/7/glfw3.so ...
; loading /usr/local/lib/chicken/7/glfw3-bindings.so ...
; loading /usr/local/lib/chicken/7/hypergiant-shaders.so ...
; loading /usr/local/lib/chicken/7/hypergiant-sprites.so ...
; loading /usr/local/lib/chicken/7/hypergiant-particles.so ...
; loading /usr/local/lib/chicken/7/hypergiant-geometry.so ...
; loading /usr/local/lib/chicken/7/hypergiant-models.so ...
; loading /usr/local/lib/chicken/7/bitstring.so ...
; loading /usr/local/lib/chicken/7/random-mtzig.so ...
#;2> Added node 0x37e96b8 to tree 0x38d1778
1 trees were visible
Rendering 1 non-alpha objects, 0 alpha objects

Warning (#<thread: thread243>): in thread: segmentation violation

    Call history:

    window.scm:88: get-keyword    
    window.scm:89: get-keyword    
    window.scm:91: glfw3-bindings#get-time    
    window.scm:163: ##sys#setter      
    window.scm:163: g871      
    window.scm:94: update     
    window.scm:95: hyperscene#update-scenes   
    window.scm:96: hyperscene#activate-camera     
    window.scm:97: hyperscene#update-cameras      
    window.scm:98: hyperscene#deactivate-camera   
    window.scm:31: opengl-glew#clear      
    window.scm:32: pre-render     
    window.scm:33: hyperscene#activate-camera     
    window.scm:34: hyperscene#render-cameras      
    hyperscene.scm:156: ##sys#gc      
    hyperscene.scm:267: g446        <--

And here's the new callstack for _csc_:

dleslie@Shodan:~/Workspace/code/hypergiant-test$ csc -lGL main.scm
dleslie@Shodan:~/Workspace/code/hypergiant-test$ ./main
Added node 0x7f1b3753c048 to tree 0x7f1b3729b048
1 trees were visible
Rendering 1 non-alpha objects, 0 alpha objects

Error: segmentation violation

    Call history:

    window.scm:88: get-keyword    
    window.scm:89: get-keyword    
    window.scm:91: glfw3-bindings#get-time    
    window.scm:163: ##sys#setter      
    window.scm:163: g871      
    window.scm:94: update     
    window.scm:95: hyperscene#update-scenes   
    window.scm:96: hyperscene#activate-camera     
    window.scm:97: hyperscene#update-cameras      
    window.scm:98: hyperscene#deactivate-camera   
    window.scm:31: opengl-glew#clear      
    window.scm:32: pre-render     
    window.scm:33: hyperscene#activate-camera     
    window.scm:34: hyperscene#render-cameras      
    hyperscene.scm:156: ##sys#gc      
    hyperscene.scm:267: g446        <--
dleslie commented 9 years ago

OpenGL version string: 4.4.12968 Compatibility Profile Context 14.201.1006.1002

AlexCharlton commented 9 years ago

Okay, so it looks like the problem is happening in Hyperscene, since it doesn't seem like we're making it back into Chicken after calling render-cameras. I'm going to guess that the segfault is happening in the function renderQueues located in hyperscene/src/camera.c, since that is the hairiest function that's being called. Can you add a print statement at the end of that funciton to see if control reaches the end of it? If it doesn't, then we'll have narrowed things down a good deal.

If renderQueues is the problem, then can you throw some more print statements in to narrow down where the segfault is occuring? NO_REVERSE_PAINTER isn't defined, so you can ignore that path.

Thanks, Dan :)

AlexCharlton commented 9 years ago

Hi Dan,

I just tried to reproduce this problem again, using a different system and by playing around with the stack and nursery sizes, but I didn't have any luck. I don't suppose you've made any progress?

dleslie commented 9 years ago

Sorry, I haven't had a chance.

I just recently reinstalled Chicken and HyperGiant. (HyperGiant is latest as of yesterday, Chicken is 4.9.0.1).

The issue still occurs. Behaviour for CSI and CSC is identical.

AlexCharlton commented 9 years ago

Dang, that's annoying. Any time you have a chance to throw some debug statements in, as per my comment above, just let me know :)

dleslie commented 9 years ago

Heh, I'll have to keep this in mind. :D

Negdayen commented 8 years ago

I have this same error with the tutorial. I added print statements as suggested and narrowed the problem to line 267 in camera.c, a call to renderNode that fails on node->pipeline->render(node->data);

AlexCharlton commented 8 years ago

Hi @Negdayen, thanks for the report! If you have the time, I'd like to do my best to get to the bottom of this, but it might be kind of slow and disjointed, because remote async debugging is hard!

To start, what platform are you using (OS and architecture)? Further (if Linux or Windows), what version of OpenGL? You can find this on Linux with glxinfo | grep "OpenGL version". I've no idea how to find this on Windows, or if anything even works there :D

Negdayen commented 8 years ago

Ubuntu 14.04 x86_64

$ glxinfo | grep "OpenGL version"
OpenGL version string: 4.5.13399 Compatibility Profile Context 15.20.1013

I was planning on testing it out on Windows in the near future, so I'll let you know how that goes.

Negdayen commented 8 years ago

this issue also resolved the problem here, got my brown board from the tutorial to render.

AlexCharlton commented 8 years ago

Hey @dleslie, we seem to have finally fixed this issue! Do you mind doing a reinstall of gl-utils and confirming that this works for you?