jdolan / ObjectivelyMVC

Object oriented MVC framework for OpenGL, SDL2 and GNU C. Inspired by Apple's AppKit. Zlib license.
Other
29 stars 7 forks source link

Hello example segfaults #3

Closed tapir closed 7 years ago

tapir commented 8 years ago

Here is the backtrace.

(gdb) run
Starting program: /home/tapir/Documents/Examples/hello 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
INFO: View:bindView: Instantiating View of class Panel

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6e924f3 in strchrnul () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff6e924f3 in strchrnul () from /usr/lib/libc.so.6
#1  0x00007ffff6e4ee3d in vfprintf () from /usr/lib/libc.so.6
#2  0x00007ffff6f008f5 in __vasprintf_chk () from /usr/lib/libc.so.6
#3  0x00007ffff73c97ff in ?? () from /usr/lib/libObjectively.so.0
#4  0x00007ffff73c9f74 in str () from /usr/lib/libObjectively.so.0
#5  0x00007ffff73c2948 in ?? () from /usr/lib/libObjectively.so.0
#6  0x00007ffff71b41bd in ?? () from /usr/lib/libObjectivelyMVC.so.0
#7  0x00007ffff71b471b in ?? () from /usr/lib/libObjectivelyMVC.so.0
#8  0x00007ffff71b0019 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#9  0x00007ffff71add39 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#10 0x00007ffff71b3b59 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#11 0x00007ffff71b3d83 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#12 0x00007ffff71b3917 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#13 0x00007ffff71b3975 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#14 0x0000000000401f7e in loadView (self=0x9f8540) at HelloViewController.c:196
#15 0x00007ffff71b4f4b in ?? () from /usr/lib/libObjectivelyMVC.so.0
#16 0x00007ffff71b4f98 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#17 0x00007ffff71b51f3 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#18 0x000000000040130a in main (argc=1, argv=0x7fffffffe218) at Hello.c:84

This line seems to be the culprit this->panel = (Panel *) $$(View, viewWithContentsOfFile, "HelloViewController.json", outlets);

tapir commented 8 years ago

May I ask what is $? Is that a macro?

jdolan commented 8 years ago

Oh. Nice find. So there are a couple things going on here.

  1. $$(JSONSerialization, objectWithContentsOfFile, ..) is failing in a very unfriendly way.
  2. It's failing in the first place because, when you compile ObjectivelyMVC, ./Examples/Hello is not an executable, but rather a libtool wrapper script. The actual executable is ./Examples/.libs/Hello.
  3. When the actual binary runs, it can't find "./HelloViewController.json"
jdolan commented 8 years ago

This should be working now. Please close if it works for you.

tapir commented 8 years ago

Can't build Hello example

HelloViewController.c: In function ‘loadView’:
HelloViewController.c:186:21: error: invalid initializer
  Outlet outlets[] = MakeOutlets(
                     ^
tapir commented 8 years ago

Hmm.. I don't know what happened on my linux machine but in windows I could compile it

Assertion failed: read == 1, file Data.c, line 174
jdolan commented 8 years ago

Err, well that's interesting, on both fronts. I tested the example on Debian Jessie, and it compiled cleanly and ran. As for Windows, that's bizarre. So it opened the file, and sought to the end of the file, but then failed to read it??

jdolan commented 8 years ago

Does fread on Windows always return bytes read, rather than elements of size read?

jdolan commented 8 years ago

I bet it's this.. http://stackoverflow.com/questions/11717120/unexpected-return-value-from-fread

jdolan commented 8 years ago

@tapir I updated the call to fopen to specify "rb", so hopefully this returns the right value now. Could you re-test the Hello example?

tapir commented 8 years ago

I'll test this on my linux machine so it might take couple days

tapir commented 8 years ago

This after running the libtool generated Hello script

INFO: View:bindView: Instantiating View of class Panel
INFO: View:bindView: Instantiating View of class Button
INFO: View:bindView: Instantiating View of class Button
INFO: View:bindView: Instantiating View of class Button
INFO: View:bindView: Instantiating View of class Input
INFO: View:bindView: Instantiating View of class Checkbox
DEBUG: View:bindView: Replacing View Control@0x1d96770 (0,0) 0x32 with Checkbox@0x1d96ee0 (0,0) 0x32
INFO: View:bindView: Instantiating View of class TextView
INFO: View:bindView: Instantiating View of class Select
INFO: View:bindView: Instantiating View of class Slider
INFO: View:bindView: Instantiating View of class TableView
INFO: View:bindView: Instantiating View of class CollectionView
Segmentation fault (core dumped)

And this is bt of the exe produced with gcc -o Hello.bin Hello.c HelloViewController.c -lGL -lGLU -lSDL2 -lObjectively -lObjectivelyMVC

#0  0x00000000400a1e68 in ?? ()
#1  0x00007fffee88bbb4 in ?? () from /usr/lib/libnvidia-glcore.so.370.28
#2  0x00007fffee4721c8 in ?? () from /usr/lib/libnvidia-glcore.so.370.28
#3  0x00007ffff6ea8ffa in ?? () from /usr/lib/libObjectivelyMVC.so.0
#4  0x00007ffff6eaecf4 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#5  0x00007ffff6ea8a77 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#6  0x00007ffff70bcb13 in ?? () from /usr/lib/libObjectively.so.0
#7  0x00007ffff6ea892e in ?? () from /usr/lib/libObjectivelyMVC.so.0
#8  0x00007ffff6eb01f1 in ?? () from /usr/lib/libObjectivelyMVC.so.0
#9  0x000000000040130a in main ()

Not much info I'm afraid?

jdolan commented 8 years ago

Try -O0 to see if maybe we can get some line numbers out of that backtrace?

This is strange. I can run the example on OS X and Debian, and I know Paril runs it on Win10 / VS.

tapir commented 8 years ago

Uh I forgot the -g flag for debug info, here is the culprit

#9  0x000000000040130a in main (argc=1, argv=0x7fffffffe2c8) at Hello.c:88
88          $(windowController, render);
jdolan commented 8 years ago

Is this still happening?