Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - stewart

#1
OK, it looks like LuaJIT is the problem. Using standard Lua works fine. I have 5.3.0 installed.

I reduced the offending code to the following standalone program which works under Lua but crashes under LuaJIT, so I don't think the problem is related to Solarus.


#include <lua.h>
#include <lauxlib.h>

int import_from_file(char * file_name) {
printf("import_from_file %s\n", file_name);

lua_State* l = luaL_newstate();
if (luaL_loadfile(l, file_name) != 0) {
fprintf(stderr, "Failed to load file %s: %s\n", file_name, lua_tostring(l, -1));
    lua_pop(l, 1);
return 0;
}

printf("result: %s\n", lua_tostring(l,0));
lua_close(l);
return 1;
}

int main(int argc, char ** argv) {
import_from_file("/Users/stewart/local/git/solarus-quest-editor/build/test/data/quest.dat");
}


With a few small tweaks I managed to build the quest editor, and tested it by loading ZSDX (screenshot attached). The main issue is that the math functions such as floor() are not in the std:: namespace.

One small problem is that when running a quest from the editor, the game window does not appear to receive keyboard events. For example, ZSDX gets stuck at the "press the space bar" stage. It works fine when using solarus_run.
#2
Hi,

I'm trying to build the quest editor for Mac OS.

Solarus library runs fine and ZSDX is playable, but when loading a quest I get a segfault in the lua code called from Solarus::LuaData::import_from_file:


Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008

VM Regions Near 0x8:
-->
    __TEXT                 000000010656f000-00000001067e7000 [ 2528K] r-x/rwx SM=COW  /Users/USER/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libluajit-5.1.2.dylib          0x000000010b49cf69 lua_pushfstring + 89
1   libluajit-5.1.2.dylib          0x000000010b4ab2dd luaL_loadfilex + 77
2   libsolarus.dylib              0x000000010705f0a2 Solarus::LuaData::import_from_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 50
3   solarus-quest-editor          0x00000001066be57d QuestProperties::reload() + 141
4   solarus-quest-editor          0x000000010670d31f QuestProperties::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 223
5   org.qt-project.QtCore          0x000000010be58ad8 QMetaObject::activate(QObject*, int, int, void**) + 2840
6   solarus-quest-editor          0x000000010670cb9d Quest::root_path_changed(QString const&) + 77
7   solarus-quest-editor          0x00000001066ab18f Quest::set_root_path(QString const&) + 223
8   solarus-quest-editor          0x00000001065c3668 MainWindow::open_quest(QString const&) + 88
9   solarus-quest-editor          0x0000000106694fc6 main + 822
10  libdyld.dylib                  0x00007fff9187f7e1 start + 1


Which version of LuaJIT is required for Solarus?

I'm using the git version of Solarus, and solarus-quest-editor, and release version 2.0.4 of LuaJIT.

Cheers,
  Stewart
#3
Hi again.

Just letting you know that I got it working. ;D

I was able to build the git version of the Solarus engine (1.5.0) and it seems to run fine on my Macbook running OSX 10.8.5. This involved a couple of hacks which may not be legitimate:

1) Removed the thread_local declaration in Random.cpp. Will this do bad things?
2) There is problem with copy constructors in due to the "const" declaration on value_type in FieldValue (see error below). I removed the "const" declaration.
3) I had to force x86_64 build, since the libraries I used were built for this architecture. You could possibly do a 32-bit build, but this is no longer the default on Mac OSX.
4) I built zsdx from the git repository, but had to change the solaris version in quest.dat to 1.5, since this is what the engine (also built from git) seems to expect.


[  0%] Building CXX object CMakeFiles/solarus.dir/src/EntityData.cpp.o
In file included from /Users/stewart/local/git/solarus/src/EntityData.cpp:17:
In file included from /Users/stewart/local/git/solarus/include/solarus/EntityData.h:24:
In file included from /Users/stewart/local/git/solarus/include/solarus/lua/LuaData.h:22:
In file included from /usr/bin/../lib/c++/v1/string:434:
In file included from /usr/bin/../lib/c++/v1/algorithm:593:
/usr/bin/../lib/c++/v1/utility:256:16: error: object of type
      'Solarus::EntityData::FieldValue' cannot be assigned because its copy
      assignment operator is implicitly deleted
        second = __p.second;
               ^
/usr/bin/../lib/c++/v1/__tree:1246:35: note: in instantiation of member function
      'std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue>::operator=' requested here
                __cache->__value_ = *__first;
                                  ^
/usr/bin/../lib/c++/v1/__tree:1187:9: note: in instantiation of function
      template specialization
      'std::__1::__tree<std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue>,
      std::__1::__map_value_compare<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue,
      std::__1::less<std::__1::basic_string<char> >, true>,
      std::__1::allocator<std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue> >
      >::__assign_multi<std::__1::__tree_const_iterator<std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue>, const
      std::__1::__tree_node<std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue>, void *> *, int> >' requested here
        __assign_multi(__t.begin(), __t.end());
        ^
/usr/bin/../lib/c++/v1/map:766:21: note: in instantiation of member function
      'std::__1::__tree<std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue>,
      std::__1::__map_value_compare<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue,
      std::__1::less<std::__1::basic_string<char> >, true>,
      std::__1::allocator<std::__1::pair<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue> > >::operator=' requested here
            __tree_ = __m.__tree_;
                    ^
/Users/stewart/local/git/solarus/include/solarus/EntityData.h:38:19: note: in
      instantiation of member function
      'std::__1::map<std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue,
      std::__1::less<std::__1::basic_string<char> >,
      std::__1::allocator<std::__1::pair<const std::__1::basic_string<char>,
      Solarus::EntityData::FieldValue> > >::operator=' requested here
class SOLARUS_API EntityData : public LuaData {
                  ^
/Users/stewart/local/git/solarus/include/solarus/EntityData.h:66:31: note: copy
      assignment operator of 'FieldValue' is implicitly deleted because field
      'value_type' is of const-qualified type 'const
      Solarus::EntityData::EntityFieldType'
        const EntityFieldType value_type;


Here are the complete changes required to get it working.


diff --git a/cmake/AddCompilationFlags.cmake b/cmake/AddCompilationFlags.cmake
index 2002c8f..a405e93 100644
--- a/cmake/AddCompilationFlags.cmake
+++ b/cmake/AddCompilationFlags.cmake
@@ -4,6 +4,10 @@
if(MINGW)
   # To avoid a compilation error in vorbisfile.h with fseeko64.
   set(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}")
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
+#  SET (CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
+  SET (CMAKE_CXX_FLAGS "-std=c++11  -stdlib=libc++ -Wall ${CMAKE_CXX_FLAGS}")
else()
   set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
endif()
diff --git a/cmake/AddSolarusLibrary.cmake b/cmake/AddSolarusLibrary.cmake
index d5a7286..4c61419 100644
--- a/cmake/AddSolarusLibrary.cmake
+++ b/cmake/AddSolarusLibrary.cmake
@@ -414,7 +414,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   set(source_files
     ${source_files}
     src/lowlevel/apple/AppleInterface.mm
-    include/lowlevel/apple/AppleInterface.h
+    include/solarus/lowlevel/apple/AppleInterface.h
   )
endif()

diff --git a/cmake/modules/OSX.cmake b/cmake/modules/OSX.cmake
index 5660041..a8fb99f 100755
--- a/cmake/modules/OSX.cmake
+++ b/cmake/modules/OSX.cmake
@@ -20,19 +20,23 @@ string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)\\[ \t\r
string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1.\\2" SOLARUS_CURRENT_OSX_VERS

# Build architectures
+#if(NOT SOLARUS_ARCH)
+#  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.4.4")
+#    set(SOLARUS_ARCH "${SOLARUS_ARCH}i386;")
+#  endif()
+#  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.5")
+#    # WORKAROUND : LuaJIT needs additional linker flag with the 64bit build.
+#    # CMake can't set arch-specific flag with Makefile and Ninja generators fo
+#    # so make a 32bit-only build if LuaJit and i386 are requested without XCod
+#    if(XCODE OR NOT SOLARUS_USE_LUAJIT OR NOT SOLARUS_ARCH MATCHES "i386")
+#      set(SOLARUS_ARCH "${SOLARUS_ARCH}x86_64;")
+#    endif()
+#  endif()
+#endif()
if(NOT SOLARUS_ARCH)
-  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.4.4")
-    set(SOLARUS_ARCH "${SOLARUS_ARCH}i386;")
-  endif()
-  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.5")
-    # WORKAROUND : LuaJIT needs additional linker flag with the 64bit build.
-    # CMake can't set arch-specific flag with Makefile and Ninja generators for
-    # so make a 32bit-only build if LuaJit and i386 are requested without XCode
-    if(XCODE OR NOT SOLARUS_USE_LUAJIT OR NOT SOLARUS_ARCH MATCHES "i386")
-      set(SOLARUS_ARCH "${SOLARUS_ARCH}x86_64;")
-    endif()
-  endif()
+  set(SOLARUS_ARCH "${SOLARUS_ARCH}x86_64;")
endif()
+
set(CMAKE_OSX_ARCHITECTURES "${SOLARUS_ARCH}" CACHE STRING "Build architecture"

# SDK version
@@ -54,8 +58,8 @@ set(CMAKE_OSX_SYSROOT "${SOLARUS_SYSROOT}" CACHE STRING "Build

# Deployment version
if(NOT SOLARUS_DEPLOYMENT AND DEFINED SOLARUS_SYSROOT)
-  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.6")
-    set(SOLARUS_DEPLOYMENT "10.6")
+  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.7")
+    set(SOLARUS_DEPLOYMENT "10.7")
   else()
     set(SOLARUS_DEPLOYMENT "10.2")
   endif()
diff --git a/include/solarus/EntityData.h b/include/solarus/EntityData.h
index 9c2e1bf..1b06225 100644
--- a/include/solarus/EntityData.h
+++ b/include/solarus/EntityData.h
@@ -63,7 +63,8 @@ class SOLARUS_API EntityData : public LuaData {
         bool operator==(const FieldValue& other) const;
         bool operator!=(const FieldValue& other) const;

-        const EntityFieldType value_type;
+//        const EntityFieldType value_type;
+        EntityFieldType value_type;
         std::string string_value;
         int int_value;  // Also used for boolean.
     };
diff --git a/src/lowlevel/QuestFiles.cpp b/src/lowlevel/QuestFiles.cpp
index 6252085..01dfef2 100644
--- a/src/lowlevel/QuestFiles.cpp
+++ b/src/lowlevel/QuestFiles.cpp
@@ -29,7 +29,7 @@
#endif

#if defined(SOLARUS_OSX) || defined(SOLARUS_IOS)
-#   include "lowlevel/apple/AppleInterface.h"
+#   include "solarus/lowlevel/apple/AppleInterface.h"
#endif

namespace Solarus {
diff --git a/src/lowlevel/Random.cpp b/src/lowlevel/Random.cpp
index 770e154..590e2fb 100644
--- a/src/lowlevel/Random.cpp
+++ b/src/lowlevel/Random.cpp
@@ -18,6 +18,8 @@
#include <ctime>
#include <random>

+#define thread_local
+
namespace Solarus {
namespace Random {

diff --git a/src/lowlevel/apple/AppleInterface.mm b/src/lowlevel/apple/AppleInte
index b572068..48f15c0 100755
--- a/src/lowlevel/apple/AppleInterface.mm
+++ b/src/lowlevel/apple/AppleInterface.mm
@@ -14,7 +14,7 @@
  * You should have received a copy of the GNU General Public License along
  * with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-#include "lowlevel/apple/AppleInterface.h"
+#include "solarus/lowlevel/apple/AppleInterface.h"

#if defined(SOLARUS_OSX) || defined(SOLARUS_IOS)

#4
OK, I messed around a bit with the CMAKE settings (diffs below) and got a little further.

One issue: The use of C++11 via libc++ restricts you to Mac OSX version at least 10.7.

Another issue: it looks like thread-local storage may be disabled for the C++11 library.

http://stackoverflow.com/questions/23791060/c-thread-local-storage-clang-503-0-40-mac-osx


Building CXX object CMakeFiles/solarus.dir/src/lowlevel/Random.cpp.o
/Users/stewart/local/git/solarus/src/lowlevel/Random.cpp:74:3: error:
      thread-local storage is unsupported for the current target
  thread_local std::mt19937 engine(std::time(nullptr));
  ^


Diffs so far:

diff --git a/cmake/AddCompilationFlags.cmake b/cmake/AddCompilationFlags.cmake
index 2002c8f..a405e93 100644
--- a/cmake/AddCompilationFlags.cmake
+++ b/cmake/AddCompilationFlags.cmake
@@ -4,6 +4,10 @@
if(MINGW)
   # To avoid a compilation error in vorbisfile.h with fseeko64.
   set(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}")
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
+#  SET (CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
+  SET (CMAKE_CXX_FLAGS "-std=c++11  -stdlib=libc++ -Wall ${CMAKE_CXX_FLAGS}")
else()
   set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
endif()
diff --git a/cmake/AddSolarusLibrary.cmake b/cmake/AddSolarusLibrary.cmake
index d5a7286..4c61419 100644
--- a/cmake/AddSolarusLibrary.cmake
+++ b/cmake/AddSolarusLibrary.cmake
@@ -414,7 +414,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   set(source_files
     ${source_files}
     src/lowlevel/apple/AppleInterface.mm
-    include/lowlevel/apple/AppleInterface.h
+    include/solarus/lowlevel/apple/AppleInterface.h
   )
endif()

diff --git a/cmake/modules/OSX.cmake b/cmake/modules/OSX.cmake
index 5660041..8f96327 100755
--- a/cmake/modules/OSX.cmake
+++ b/cmake/modules/OSX.cmake
@@ -54,8 +54,8 @@ set(CMAKE_OSX_SYSROOT "${SOLARUS_SYSROOT}" CACHE STRING "Build

# Deployment version
if(NOT SOLARUS_DEPLOYMENT AND DEFINED SOLARUS_SYSROOT)
-  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.6")
-    set(SOLARUS_DEPLOYMENT "10.6")
+  if(NOT ${SOLARUS_CURRENT_OSX_VERSION_LONG} VERSION_LESS "10.7")
+    set(SOLARUS_DEPLOYMENT "10.7")
   else()
     set(SOLARUS_DEPLOYMENT "10.2")
   endif()
diff --git a/src/lowlevel/QuestFiles.cpp b/src/lowlevel/QuestFiles.cpp
index 6252085..01dfef2 100644
--- a/src/lowlevel/QuestFiles.cpp
+++ b/src/lowlevel/QuestFiles.cpp
@@ -29,7 +29,7 @@
#endif

#if defined(SOLARUS_OSX) || defined(SOLARUS_IOS)
-#   include "lowlevel/apple/AppleInterface.h"
+#   include "solarus/lowlevel/apple/AppleInterface.h"
#endif

namespace Solarus {

#5
As far as I can tell, C++11 is not supported by the standard g++ compiler on Mac OSX.  :(

It looks like you have to:
1) use clang++ rather than g++
2) link against libc++

http://stackoverflow.com/questions/14228856/how-to-compile-c-with-c11-support-in-mac-terminal
http://blog.michael.kuron-germany.de/2013/02/using-c11-on-mac-os-x-10-8/
#6
Hi,

Looks like the current version 1.4.2 is only available for download for Windows. I tried loading the ALTTP resources in the latest Mac version and it didn't work. Therefore, I'm trying to build the library and editor for Mac OSX.

I ran into a couple of issues:

While running 'cmake':

1) Missing source file in cmake build


CMake Error at cmake/AddSolarusLibrary.cmake:422 (add_library):
  Cannot find source file:

    include/lowlevel/apple/AppleInterface.h

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx
Call Stack (most recent call first):
  CMakeLists.txt:9 (include)


This can be fixed by:


@@ -414,7 +414,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   set(source_files
     ${source_files}
     src/lowlevel/apple/AppleInterface.mm
-    include/lowlevel/apple/AppleInterface.h
+    include/solarus/lowlevel/apple/AppleInterface.h
   )
endif()


2) MACOS_RPATH warning:


CMake Warning (dev):
  Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
  --help-policy CMP0042" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  MACOSX_RPATH is not specified for the following targets:

   solarus
   solarus_testing

This warning is for project developers.  Use -Wno-dev to suppress it.


As the warning says, this can be suppressed using -Wno-dev, and cmake will complete successfully.

While running 'make':

3) Many errors regarding STL templates...


Scanning dependencies of target solarus
[  1%] Building CXX object CMakeFiles/solarus.dir/src/entities/AnimatedTilePattern.cpp.o
In file included from /Users/stewart/local/git/solarus/src/entities/AnimatedTilePattern.cpp:17:
In file included from /Users/stewart/local/git/solarus/include/solarus/entities/AnimatedTilePattern.h:21:
In file included from /Users/stewart/local/git/solarus/include/solarus/entities/TilePattern.h:22:
/Users/stewart/local/git/solarus/include/solarus/lowlevel/SurfacePtr.h:29:25: error:
      no type named 'shared_ptr' in namespace 'std'
using SurfacePtr = std::shared_ptr<Surface>;
                   ~~~~~^


This appears to be related to Apple's support for STL. For example, see here:
http://stackoverflow.com/questions/13445742/apple-and-shared-ptr
and
http://stackoverflow.com/questions/12819886/no-type-named-shared-ptr-in-namespace-std

Any ideas what to do about this? I am not very familiar with C++/STL or cmake so its a bit hard for me to debug this.

Cheers,
  Stewart