Closed alexispurslane closed 9 years ago
Hey @christopherdumas, sorry for the late reply.
I don't have a Mac, but the I've seen segmentation faults with Console::wait_for_keypress
(mac and linux) before when using libtcod version 1.6.0
(the current development version): https://github.com/tomassedovic/tcod-rs/issues/37
Can you check the libtcod version you're using (I'm guessing you compiled it yourself since there are no official Mac binary releases). We only support 1.5.1
(stable) currently and 1.5.2
seems to work, but 1.6.0
introduced a breaking change in the keyboard struct.
If you just cloned libtcod from its repo, you'll be on 1.6.0 by default. Can you try compiling this instead?
Ok, sorry it took me so long to answer. Im using 1.5.2
I'm really sorry but I can't figure out what's wrong :-(.
I tried your example with libtcod 1.5.2 (on linux) and it works for me. I checked the libtcod code and I can't find anything that would cause a segfault.
I'm definitely getting a segfault with 1.6.0, though. Can you double-check that you're not using 1.6.0? Could it maybe be that you have the wrong version in the target
directory (cargo doesn't rebuild native dependencies if they're already there)? I know this is a stupid thing to ask, but people make mistakes and I've already had someone else claiming to use 1.5.2 when they were in fact using 1.6.0...
Other than that, I'm not sure what to do. How exactly are you compiling libtcod?
I am compiling libtcod from source.
cd libtcod
wget https://gist.githubusercontent.com/jaredonline/daf3c5f1ea6c7ca00e29/raw/ae91b3e47bf0de5b772eff882e477d8144cfbaf8/makefile-osx -O makefiles/makefile-osx
wget https://dl.dropboxusercontent.com/u/169446/osx.tar.gz
tar -xzvf osx.tar.gz
make -f makefiles/makefile-osx
make -f makefiles/makefile-samples-linux
Hey there @christopherdumas it looks like you're following my tutorial on getting this working.
If you just used the commands straight through it, you'll need to add a new step (which isn't documented in my blog).
After
cd libtcode
You should do
hg checkout 1.5.x
And then follow the rest of the steps like normal.
:open_mouth: Thanks! BTW Awesome tutorial!
@jaredonline: this pull request should do the same thing in the README here, right?
https://github.com/tomassedovic/tcod-rs/pull/48
(btw, when I have a bit more time, I'll write a proper Cargo build script, which will fetch the right source and build everything, can't do that right now though)
@tomassedovic left a comment on that PR!
@christopherdumas so was that it? Does Console::wait_for_keypress
work now?
Im still getting a crash. Are there any other changes that I need to make?
I changed the build script to point at my new installation of libtcod 1.5.x, buuuut it still crashes after any key press.
@christopherdumas make sure you delete your existing target
directory, it doesn't get rebuilt.
cargo clean
should take care of that for you.
When I try to compile libtcod again becouse cargo can't find it, I get this:
@christopherdumas are you doing this on Linux?
Oh nvm. I re-read my own instructions [-;
No, I am not on linux. I am on Max OSX Yosemite.
Anyway, look at my machine specs that I posted in the original issue post:
Model: MacBookPro11,1, BootROM MBP111.0138.B11, 2 processors, Intel Core i5, 2.4 GHz, 16 GB, SMC 2.16f68
Graphics: Intel Iris, Intel Iris, Built-In
@christopherdumas I'm running into issues trying to get a fresh install to compile as well. I'll do some digging, but I'm fairly busy today. Will update soon I hope.
Thank you!
Ill work on it to, and if I find anything I'll let you guys know.
I was unable to get 1.5.x to compile on OSX either. I can compile 1.6.0 with the makefile provided, though.
Additionally, I tracked the segfault down to this commit: https://bitbucket.org/jice/libtcod/commits/7a8b072365b5cb4253b18a248890ce0c414c5f11
A text field of length TCOD_KEY_TEXT_SIZE was added to the TCOD_key_t struct, which is what's returned from wait for keypress, which is why it segfaults trying to access fields on the struct.
I made a little hack to tcod-rs as seen in this commit: https://github.com/pmsanford/tcod-rs/commit/d8bdda31a8e6296e2be84b7c8fcd356c2d877381 this got tcod-rs limping along with 1.6.0 well enough to complete the existing chapters of @jaredonline's tutorial (but I'm sure there are some other 1.6.0 landmines out there).
Hopefully this gives you enough to get going for now :)
Thanks alot!
Okay, this is a bit strange. There don't seem to be any new commits to the 1.5.x branch since February this 2014 so why would it suddenly stop compiling?
@mtsr you mentioned having some issues compiling 1.5.1 a month ago. Any chance the folks here are seeing the same thing?
I'm not categorically opposed to switching to 1.6.0, but afaik most existing libtcod users, tutorials and bindings are on the 1.5.x branch so this makes me a bit uneasy. Then again, this is Rust, we're all used to breakage on daily basis ;-).
So: I'd prefer if we could figure out how to compile 1.5.x and then codify that in the crossplatform build script (issue 32). If not, I guess we'll have to switch to 1.6.0.
@tomassedovic Could you start a new branch and new major version for tcod-rs
that is 1.6.0 compatible? Maybe in an alpha
state? Future deving goes on 1.6.0, maintain the current major version on 1.5.x? Is that too much maintenance for you?
Yeah, I guess I could. I didn't know how to make both versions available through Cargo, but you can totally do that by adding branch = whatever
under the dependency. That won't work for crates.io but we can figure that out later.
I should have some free time coming up soon; I'll see if I can figure out why 1.5.x doesn't want to build on OSX. I started working on this after I upgraded to Yosemite and was never able to get that branch to build. Maybe there was some change external to libtcod?
Thanks @pmsanford, that's what I'm suspecting, too.
Anyway, here's a libtcod-1.6.0
branch: https://github.com/tomassedovic/tcod-rs/tree/libtcod-1.6.0
I cherry-picked your commit, hope you don't mind (if you do, let me know).
Adding this to a project that wishes to use it seems to work:
[dependencies.tcod]
git = "https://github.com/tomassedovic/tcod-rs"
branch = "libtcod-1.6.0"
I'll try to maintain both. As usual, patches & bug reports are very much appreciated!
I ended up having the 1.5.0 branch compile fine. I did have to search for a makefile that worked for me, though. I remember finding a fix somewhere, but I don't remember where.
I used the osx.tar.gz file, which adds these files:
osx/hmtool_Info.plist
osx/macsupport.h
osx/macsupport.m
and this makefile-osx:
# libtcod makefile
# to build debug version, run "make -f makefile-linux debug"
# to build release version, run "make -f makefile-linux release"
SRCDIR=src
INCDIR=include
#dependencies
# SDL
SDL_FLAGS=`sdl-config --cflags`
SDL_LIBS=`sdl-config --libs`
# ZLIB
ZLIB_FLAGS=
ZLIB_LIBS=-lz
#OPENGL
OPENGL_LIB=-framework OpenGL
# Mac support
OSXCOMPAT = osx/macsupport.m -framework Cocoa
CFLAGS=$(FLAGS) -I$(INCDIR) -I$(INCDIR)/gui -Wall $(SDL_FLAGS) $(ZLIB_FLAGS) -fno-strict-aliasing -fPIC -ansi
TEMP=/tmp
CC=gcc
CPP=g++
.SUFFIXES: a .o .h .c
$(TEMP)/libtcod/release/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) -DNDEBUG -O2 -s -o $@ -c $<
$(TEMP)/libtcod/release/%.o : $(SRCDIR)/%.cpp
$(CPP) $(CFLAGS) -DNDEBUG -O2 -s -o $@ -c $<
$(TEMP)/libtcod/release/gui/%.o : $(SRCDIR)/gui/%.cpp
$(CPP) $(CFLAGS) -DNDEBUG -O2 -s -o $@ -c $<
$(TEMP)/libtcod/debug/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) -g -o $@ -c $<
$(TEMP)/libtcod/debug/%.o : $(SRCDIR)/%.cpp
$(CPP) $(CFLAGS) -g -o $@ -c $<
$(TEMP)/libtcod/debug/gui/%.o : $(SRCDIR)/gui/%.cpp
$(CPP) $(CFLAGS) -g -o $@ -c $<
LIBOBJS_C_DEBUG= \
$(TEMP)/libtcod/debug/bresenham_c.o \
$(TEMP)/libtcod/debug/bsp_c.o \
$(TEMP)/libtcod/debug/color_c.o \
$(TEMP)/libtcod/debug/console_c.o \
$(TEMP)/libtcod/debug/fov_c.o \
$(TEMP)/libtcod/debug/fov_circular_raycasting.o \
$(TEMP)/libtcod/debug/fov_diamond_raycasting.o \
$(TEMP)/libtcod/debug/fov_recursive_shadowcasting.o \
$(TEMP)/libtcod/debug/fov_permissive2.o \
$(TEMP)/libtcod/debug/fov_restrictive.o \
$(TEMP)/libtcod/debug/heightmap_c.o \
$(TEMP)/libtcod/debug/image_c.o \
$(TEMP)/libtcod/debug/lex_c.o \
$(TEMP)/libtcod/debug/list_c.o \
$(TEMP)/libtcod/debug/mersenne_c.o \
$(TEMP)/libtcod/debug/noise_c.o \
$(TEMP)/libtcod/debug/parser_c.o \
$(TEMP)/libtcod/debug/path_c.o \
$(TEMP)/libtcod/debug/sys_c.o \
$(TEMP)/libtcod/debug/sys_opengl_c.o \
$(TEMP)/libtcod/debug/sys_sdl_c.o \
$(TEMP)/libtcod/debug/sys_sdl_img_bmp.o \
$(TEMP)/libtcod/debug/sys_sdl_img_png.o \
$(TEMP)/libtcod/debug/tree_c.o \
$(TEMP)/libtcod/debug/txtfield_c.o \
$(TEMP)/libtcod/debug/wrappers.o \
$(TEMP)/libtcod/debug/zip_c.o \
$(TEMP)/libtcod/debug/namegen_c.o \
$(TEMP)/libtcod/debug/png/lodepng.o
LIBOBJS_CPP_DEBUG= \
$(TEMP)/libtcod/debug/bresenham.o \
$(TEMP)/libtcod/debug/bsp.o \
$(TEMP)/libtcod/debug/color.o \
$(TEMP)/libtcod/debug/console.o \
$(TEMP)/libtcod/debug/fov.o \
$(TEMP)/libtcod/debug/heightmap.o \
$(TEMP)/libtcod/debug/image.o \
$(TEMP)/libtcod/debug/lex.o \
$(TEMP)/libtcod/debug/mersenne.o \
$(TEMP)/libtcod/debug/mouse.o \
$(TEMP)/libtcod/debug/noise.o \
$(TEMP)/libtcod/debug/parser.o \
$(TEMP)/libtcod/debug/path.o \
$(TEMP)/libtcod/debug/sys.o \
$(TEMP)/libtcod/debug/txtfield.o \
$(TEMP)/libtcod/debug/zip.o \
$(TEMP)/libtcod/debug/namegen.o
GUIOBJS_DEBUG= \
$(TEMP)/libtcod/debug/gui/button.o \
$(TEMP)/libtcod/debug/gui/container.o \
$(TEMP)/libtcod/debug/gui/flatlist.o \
$(TEMP)/libtcod/debug/gui/hbox.o \
$(TEMP)/libtcod/debug/gui/image.o \
$(TEMP)/libtcod/debug/gui/label.o \
$(TEMP)/libtcod/debug/gui/radiobutton.o \
$(TEMP)/libtcod/debug/gui/slider.o \
$(TEMP)/libtcod/debug/gui/statusbar.o \
$(TEMP)/libtcod/debug/gui/textbox.o \
$(TEMP)/libtcod/debug/gui/togglebutton.o \
$(TEMP)/libtcod/debug/gui/toolbar.o \
$(TEMP)/libtcod/debug/gui/vbox.o \
$(TEMP)/libtcod/debug/gui/widget.o
LIBOBJS_C_RELEASE= \
$(TEMP)/libtcod/release/bresenham_c.o \
$(TEMP)/libtcod/release/bsp_c.o \
$(TEMP)/libtcod/release/color_c.o \
$(TEMP)/libtcod/release/console_c.o \
$(TEMP)/libtcod/release/fov_c.o \
$(TEMP)/libtcod/release/fov_circular_raycasting.o \
$(TEMP)/libtcod/release/fov_diamond_raycasting.o \
$(TEMP)/libtcod/release/fov_recursive_shadowcasting.o \
$(TEMP)/libtcod/release/fov_permissive2.o \
$(TEMP)/libtcod/release/fov_restrictive.o \
$(TEMP)/libtcod/release/heightmap_c.o \
$(TEMP)/libtcod/release/image_c.o \
$(TEMP)/libtcod/release/lex_c.o \
$(TEMP)/libtcod/release/list_c.o \
$(TEMP)/libtcod/release/mersenne_c.o \
$(TEMP)/libtcod/release/noise_c.o \
$(TEMP)/libtcod/release/parser_c.o \
$(TEMP)/libtcod/release/path_c.o \
$(TEMP)/libtcod/release/sys_c.o \
$(TEMP)/libtcod/release/sys_opengl_c.o \
$(TEMP)/libtcod/release/sys_sdl_c.o \
$(TEMP)/libtcod/release/sys_sdl_img_bmp.o \
$(TEMP)/libtcod/release/sys_sdl_img_png.o \
$(TEMP)/libtcod/release/txtfield_c.o \
$(TEMP)/libtcod/release/tree_c.o \
$(TEMP)/libtcod/release/wrappers.o \
$(TEMP)/libtcod/release/zip_c.o \
$(TEMP)/libtcod/release/namegen_c.o \
$(TEMP)/libtcod/release/png/lodepng.o
LIBOBJS_CPP_RELEASE= \
$(TEMP)/libtcod/release/bresenham.o \
$(TEMP)/libtcod/release/bsp.o \
$(TEMP)/libtcod/release/color.o \
$(TEMP)/libtcod/release/console.o \
$(TEMP)/libtcod/release/fov.o \
$(TEMP)/libtcod/release/heightmap.o \
$(TEMP)/libtcod/release/image.o \
$(TEMP)/libtcod/release/lex.o \
$(TEMP)/libtcod/release/mersenne.o \
$(TEMP)/libtcod/release/mouse.o \
$(TEMP)/libtcod/release/noise.o \
$(TEMP)/libtcod/release/parser.o \
$(TEMP)/libtcod/release/path.o \
$(TEMP)/libtcod/release/sys.o \
$(TEMP)/libtcod/release/txtfield.o \
$(TEMP)/libtcod/release/zip.o \
$(TEMP)/libtcod/release/namegen.o
GUIOBJS_RELEASE= \
$(TEMP)/libtcod/release/gui/button.o \
$(TEMP)/libtcod/release/gui/container.o \
$(TEMP)/libtcod/release/gui/flatlist.o \
$(TEMP)/libtcod/release/gui/hbox.o \
$(TEMP)/libtcod/release/gui/image.o \
$(TEMP)/libtcod/release/gui/label.o \
$(TEMP)/libtcod/release/gui/radiobutton.o \
$(TEMP)/libtcod/release/gui/slider.o \
$(TEMP)/libtcod/release/gui/statusbar.o \
$(TEMP)/libtcod/release/gui/textbox.o \
$(TEMP)/libtcod/release/gui/togglebutton.o \
$(TEMP)/libtcod/release/gui/toolbar.o \
$(TEMP)/libtcod/release/gui/vbox.o \
$(TEMP)/libtcod/release/gui/widget.o
all : debug release
debug : libtcod_debug.dylib libtcodxx_debug.dylib libtcodgui_debug.dylib
release : libtcod.dylib libtcodxx.dylib libtcodgui.dylib
$(TEMP)/libtcod/debug/png :
mkdir -p $@
$(TEMP)/libtcod/debug/gui :
mkdir -p $@
$(TEMP)/libtcod/release/png :
mkdir -p $@
$(TEMP)/libtcod/release/gui :
mkdir -p $@
libtcod.a : $(LIBOBJS_C_DEBUG)
ar r $@ $(LIBOBJS_C_DEBUG)
libtcodxx.a : $(LIBOBJS_CPP_DEBUG)
ar r $@ $(LIBOBJS_CPP_DEBUG)
libtcod.dylib : $(TEMP)/libtcod/release/png $(LIBOBJS_C_RELEASE)
g++ -shared -Wl,-install_name,$@ -o $@ $(LIBOBJS_C_RELEASE) $(OSXCOMPAT) $(ZLIB_LIBS) $(SDL_LIBS) $(CFLAGS) $(OPENGL_LIB)
libtcodxx.dylib : $(TEMP)/libtcod/release/png $(LIBOBJS_CPP_RELEASE)
g++ -shared -Wl,-install_name,$@ -o $@ $(LIBOBJS_CPP_RELEASE) $(OSXCOMPAT) -L. -ltcod $(CFLAGS)
libtcodgui.dylib : $(TEMP)/libtcod/release/gui $(GUIOBJS_RELEASE)
g++ -shared -Wl,-install_name,$@ -o $@ $(GUIOBJS_RELEASE) $(OSXCOMPAT) -L. -ltcod -ltcodxx $(CFLAGS)
libtcod_debug.dylib : $(TEMP)/libtcod/debug/png $(LIBOBJS_C_DEBUG)
g++ -shared -Wl,-install_name,$@ -o $@ $(LIBOBJS_C_DEBUG) $(OSXCOMPAT) $(ZLIB_LIBS) $(SDL_LIBS) $(CFLAGS) $(OPENGL_LIB)
libtcodxx_debug.dylib : $(TEMP)/libtcod/debug/png $(LIBOBJS_CPP_DEBUG)
g++ -shared -Wl,-install_name,$@ -o $@ $(LIBOBJS_CPP_DEBUG) $(OSXCOMPAT) -L. -ltcod_debug $(CFLAGS)
libtcodgui_debug.dylib : $(TEMP)/libtcod/debug/gui $(GUIOBJS_DEBUG)
g++ -shared -Wl,-install_name,$@ -o $@ $(GUIOBJS_DEBUG) $(OSXCOMPAT) -L. -ltcod_debug -ltcodxx_debug $(CFLAGS)
clean :
\rm -f $(LIBOBJS_C_RELEASE) $(LIBOBJS_CPP_RELEASE) $(GUIOBJS_RELEASE) $(LIBOBJS_C_DEBUG) $(LIBOBJS_CPP_DEBUG) $(GUIOBJS_DEBUG) libtcod.a libtcodxx.a libtcod.dylib libtcodxx.dylib libtcodgui.dylib libtcod_debug.dylib libtcodxx_debug.dylib libtcodgui_debug.dylib libtcodpy.pyc
Well, that was quicker than I thought. The version of the OSX Makefile from the tutorial contains a reference to an object file only built in the 1.6.0 branch, sys_sdl12_c.o
If you remove that line it works. Here's an updated gist with a revision where you can see the change: https://gist.github.com/pmsanford/6d6e4f46140ef23ffdd9/revisions
I tested this dylib with all the tcod-rs examples as well as my version of @jaredonline's roguelike code and it seems to work fine.
\o/ Thanks!
Hey so this is totally just a hacky proof of concept, but here's a branch which switches to the newstyle build scripts:
https://github.com/tomassedovic/tcod-rs/pull/51
It bundles the latest checkout of libtcod 1.5.x plus the makefile and osx files provided by @jaredonline and @pmsanford.
Once this lands, the new workflow everywhere will be this:
Using tcod-rs in another app would mean:
[dependencies.tcod]
git = "https://github.com/tomassedovic/tcod-rs.git"
And that should just always work. If you have the libtcod library already built / downloaded, you can use Cargo's override system to skip the tcod-sys's build script completely:
http://doc.crates.io/build-script.html#case-study:-linking-to-system-libraries
Would any of your Mac folks be willing to try this out? Just run steps 1. to 4. Hopefully, it'll just work. If not, we'll try to figure it out.
I will at some point when I get a chance.
So that pull request (https://github.com/tomassedovic/tcod-rs/pull/51) now contains an updated README listing instructions on linux, windows and mac and travis is working again.
Okay, the build script stuff is merged and regardless, seems that this issue is ready be closed. We should have a much more repeatable way to build tcod-rs (on all platforms).
Thanks to everyone involved in this thread!
Here is the code:
My computer:
It gets to the screen with the '@', but once I press any key, it crashes! Pic: