workaround win32 crash + fix some more valgrind warnings #7

Open
wants to merge 7 commits into
from
View
10 .travis.yml
@@ -0,0 +1,10 @@
+language: cpp
+compiler:
+ - gcc
+ - clang
+before_script:
+ - sudo apt-get install libdevil-dev libmagick++-dev
+ - cmake .
+script:
+ - make
+
View
27 CMakeLists.txt
@@ -1,32 +1,41 @@
project(SpringMapConvNG)
cmake_minimum_required(VERSION 2.6)
-#find_package(Qt4 REQUIRED)
+
+LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+
+
if (NOT MINGW )
- include_directories(${CMAKE_CURRENT_BINARY_DIR})
+ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${IL_INCLUDE_DIR})
else ( NOT MINGW )
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/include )
link_directories( ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/lib ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH} )
-
endif ( NOT MINGW )
#qt4_automoc(${springMapConvNG_SRCS})
+find_package(ImageMagick COMPONENTS Magick++)
find_package(DevIL REQUIRED)
+include_directories(${ImageMagick_INCLUDE_DIRS})
+
add_library(mapconv SHARED CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp )
add_library(mapconv_static STATIC CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp )
add_executable(springMapConvNG main.cpp)
add_executable(smfdecompiler decompiler.cpp)
+
+set(MAPCONV_LIBS ${IL_LIBRARIES} ${ImageMagick_LIBRARIES})
+
if (NOT MINGW )
-target_link_libraries(springMapConvNG IL ILU mapconv_static )
-target_link_libraries(mapconv IL ILU )
-target_link_libraries(smfdecompiler IL ILU mapconv_static )
+ target_link_libraries(springMapConvNG mapconv_static ${MAPCONV_LIBS})
+ target_link_libraries(mapconv ${IL_LIBRARIES})
+ target_link_libraries(smfdecompiler mapconv_static ${MAPCONV_LIBS})
else ( NOT MINGW )
-target_link_libraries(springMapConvNG DevIL ILU mapconv )
-target_link_libraries(mapconv DevIL ILU )
-target_link_libraries(smfdecompiler DevIL ILU mapconv )
+ target_link_libraries(springMapConvNG mapconv ${MAPCONV_LIBS})
+ target_link_libraries(mapconv ${IL_LIBRARIES})
+ target_link_libraries(smfdecompiler mapconv ${MAPCONV_LIBS})
endif ( NOT MINGW )
install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
install(TARGETS mapconv_static ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
install(TARGETS mapconv LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
+
View
5 Image.cpp
@@ -27,8 +27,9 @@ CannotLoadImageException::CannotLoadImageException(std::string path) : runtime_e
Image::Image()
{
ilGenImages(1,&image);
-
-
+ w = 0;
+ h = 0;
+ d = 0;
}
void Image::GetRect(int x, int y, int w, int h,ILenum format, void * dest)
View
5 Image.h
@@ -23,6 +23,11 @@
#include <IL/ilu.h>
#include <string>
#include <stdexcept>
+
+#ifdef SetPixelRGBA
+#undef SetPixelRGBA
+#endif
+
class CannotLoadImageException : public std::runtime_error
{
public:
View
4 SMFMap.cpp
@@ -65,6 +65,7 @@ SMFMap::SMFMap(std::string smfname)
typemap = NULL;
minimap = NULL;
vegetationmap = NULL;
+ m_tiles = NULL;
FILE * smffile = fopen(smfname.c_str(),"rb");
if ( !smffile )
{
@@ -238,8 +239,7 @@ SMFMap::SMFMap(std::string smfname)
}
fclose(smffile);
delete [] dxt1data;
-
-
+ delete [] tilematrix;
}
void SMFMap::SetClamping(bool b)
View
6 TileStorage.cpp
@@ -58,10 +58,10 @@ void TileStorage::Reset()
{
if ( m_tiles_compressed.find((*it).first) != m_tiles_compressed.end() )
{
- delete m_tiles_compressed[(*it).first];
+ delete [] m_tiles_compressed[(*it).first];
}
- delete (*it).second;
+ delete [] (*it).second;
}
m_tiles.clear();
m_lasttiles.clear();
@@ -230,7 +230,7 @@ uint64_t TileStorage::AddTileOrGetSimiliar(uint8_t* data, float th, int compress
}else if ( compresslevel == COMPRESS_REASONABLE_BESTQUALITY )
{
float mindiff = 9999999.0f;
- uint64_t besttile;
+ uint64_t besttile = 0;
for ( std::list<uint64_t>::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++ )
{
float diff = tilediff(data,m_tiles[(*it)]);
View
2 TileStorage.h
@@ -32,7 +32,7 @@ inline uint64_t tilechecksum( uint8_t * data )
r += data[x]*63018038201L*x*x;
r ^= 13091204281L;
r *= 13091204281L*x;
- r *= 226673591177742970257407LL*data[x];
+ r *= 108086391056891903ULL*data[x];
}
Crc32 c;
c.AddData(data,32*32*4);
View
143 cmake/FindDevIL.cmake
@@ -0,0 +1,143 @@
+# Downloaded from: http://www-id.imag.fr/FLOWVR/manual/flowvr-suite-src/flowvr-render/cmake/
+# License: GPL v2, http://www-id.imag.fr/FLOWVR/manual/flowvr-suite-src/flowvr-render/COPYING
+#
+# Modifications:
+# 2008.01.16 Tobi Vollebregt -- changed Devil->DEVIL for consistency
+# -- added devil, ilu, ilut alternative names for MinGW
+# -- removed "looking for devil" status message
+
+# - Find DevIL
+# Find the native DevIL includes and libraries.
+#
+# IL_INCLUDE_DIR - Where to find "IL/il.h", "IL/ilu.h" and "IL/ilut.h"
+# IL_IL_LIBRARY - Path to the IL shared library
+# IL_ILU_LIBRARY - Path to the ILU shared library
+# IL_ILUT_LIBRARY - Path to the ILUT shared library
+# IL_LIBRARIES - List of libraries when using IL
+# IL_FOUND - True if IL is found.
+
+INCLUDE(FindPackageHandleStandardArgs)
+
+IF (IL_INCLUDE_DIR AND IL_IL_LIBRARY)
+ # Already in cache, be silent
+ SET(DevIL_FIND_QUIETLY TRUE)
+ENDIF (IL_INCLUDE_DIR AND IL_IL_LIBRARY)
+
+
+
+set(IL_FIND_LIB_STD_ARGS
+ PATH_SUFFIXES
+ lib64
+ lib
+ libs64
+ libs
+ libs/Win32
+ libs/Win64
+ PATHS
+ ${PROJECT_BINARY_DIR}
+ ${PROJECT_SOURCE_DIR}
+ $ENV{LD_LIBRARY_PATH}
+ $ENV{LIBRARY_PATH}
+ /usr
+ /usr/local
+ /usr/bin
+ )
+
+FIND_LIBRARY(IL_IL_LIBRARY
+ NAMES
+ IL
+ devil
+ DevIL
+ ${IL_FIND_LIB_STD_ARGS}
+)
+
+FIND_LIBRARY(IL_ILU_LIBRARY
+ NAMES
+ ilu
+ ILU
+ ${IL_FIND_LIB_STD_ARGS}
+)
+
+FIND_LIBRARY(IL_ILUT_LIBRARY
+ NAMES
+ ilut
+ ILUT
+ ${IL_FIND_LIB_STD_ARGS}
+)
+
+SET(IL_LIBRARIES "")
+IF (IL_IL_LIBRARY)
+ LIST(APPEND IL_LIBRARIES ${IL_IL_LIBRARY})
+ENDIF (IL_IL_LIBRARY)
+IF (IL_ILU_LIBRARY)
+ LIST(APPEND IL_LIBRARIES ${IL_ILU_LIBRARY})
+ENDIF (IL_ILU_LIBRARY)
+IF (IL_ILUT_LIBRARY)
+ LIST(APPEND IL_LIBRARIES ${IL_ILUT_LIBRARY})
+ENDIF (IL_ILUT_LIBRARY)
+
+GET_FILENAME_COMPONENT(IL_LIBRARY_DIR "${IL_IL_LIBRARY}" PATH)
+GET_FILENAME_COMPONENT(IL_LIBRARY_SUPER_DIR "${IL_LIBRARY_DIR}" PATH)
+
+
+
+set(IL_FIND_HEADER_STD_ARGS
+ PATHS
+ ${PROJECT_BINARY_DIR}/include
+ ${PROJECT_SOURCE_DIR}/include
+ ${IL_LIBRARY_SUPER_DIR}/include
+ $ENV{CPATH}
+ /usr/local/include
+ /usr/include
+ NO_DEFAULT_PATH
+ )
+
+FIND_FILE(IL_IL_HEADER IL/il.h
+ ${IL_FIND_INCLUDE_STD_ARGS}
+)
+
+FIND_FILE(IL_ILU_HEADER IL/ilu.h
+ ${IL_FIND_INCLUDE_STD_ARGS}
+)
+
+FIND_FILE(IL_ILUT_HEADER IL/ilut.h
+ ${IL_FIND_INCLUDE_STD_ARGS}
+)
+
+FIND_PATH(IL_INCLUDE_DIR IL/il.h
+ ${IL_FIND_INCLUDE_STD_ARGS}
+)
+
+
+
+# handle the QUIETLY and REQUIRED arguments and set IL_FOUND to TRUE if
+# all listed variables are TRUE
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(DevIL DEFAULT_MSG IL_IL_HEADER IL_INCLUDE_DIR IL_IL_LIBRARY IL_LIBRARIES)
+
+IF (IL_ILU_HEADER AND IL_ILU_LIBRARY)
+ SET(IL_ILU_FOUND TRUE)
+ IF (NOT DevIL_FIND_QUIETLY)
+ MESSAGE(STATUS "Found DevIL-ILU: ${IL_ILU_LIBRARY} - ${IL_ILU_HEADER}")
+ ENDIF (NOT DevIL_FIND_QUIETLY)
+ELSE (IL_ILU_HEADER AND IL_ILU_LIBRARY)
+ SET(IL_ILU_FOUND FALSE)
+ENDIF (IL_ILU_HEADER AND IL_ILU_LIBRARY)
+
+IF (IL_ILUT_HEADER AND IL_ILUT_LIBRARY)
+ SET(IL_ILUT_FOUND TRUE)
+ IF (NOT DevIL_FIND_QUIETLY)
+ MESSAGE(STATUS "Found DevIL-ILUT: ${IL_ILUT_LIBRARY} - ${IL_ILUT_HEADER}")
+ ENDIF (NOT DevIL_FIND_QUIETLY)
+ELSE (IL_ILUT_HEADER AND IL_ILUT_LIBRARY)
+ SET(IL_ILUT_FOUND FALSE)
+ENDIF (IL_ILUT_HEADER AND IL_ILUT_LIBRARY)
+
+
+
+MARK_AS_ADVANCED(
+ IL_INCLUDE_DIR
+ IL_IL_LIBRARY
+ IL_ILU_LIBRARY
+ IL_ILUT_LIBRARY
+ IL_LIBRARIES
+ )
View
7 decompiler.cpp
@@ -1,4 +1,4 @@
-#include <IL/il.h>
+#include <Magick++.h>
#include <iostream>
#include <string.h>
#include "SMFMap.h"
@@ -8,6 +8,8 @@
#include <windows.h>
#include <direct.h>
#include <io.h>
+#else
+#include <unistd.h>
#endif
void help(char ** argv)
{
@@ -16,7 +18,7 @@ void help(char ** argv)
}
int main(int argc, char** argv)
{
- ilInit();
+ Magick::InitializeMagick(*argv);
if ( argc == 1 )
{
@@ -85,6 +87,7 @@ int main(int argc, char** argv)
}
SMFMap * m = new SMFMap(mapfile);
m->SaveSourceFiles();
+ delete m;
}
}
View
15 main.cpp
@@ -1,6 +1,7 @@
#include <IL/il.h>
+#include <Magick++.h>
#include <iostream>
#include <string.h>
#include "SMFMap.h"
@@ -16,9 +17,22 @@ void help(char ** argv)
std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl;
}
+/*
+static void* ILAPIENTRY AllocFunc(const ILsizei Size)
+{
+ return malloc(Size);
+}
+static void ILAPIENTRY FreeFunc(const void * CONST_RESTRICT ptr)
+{
+ free((void*)ptr);
+}
+
+*/
int main(int argc, char** argv)
{
+// ilSetMemory(AllocFunc, FreeFunc); //FIXME: remove this, workaround weird win32 crash
ilInit();
+ Magick::InitializeMagick(*argv);
if ( argc == 1 )
{
@@ -239,6 +253,7 @@ int main(int argc, char** argv)
}
m->Compile();
+ delete m;
}
}