Skip to content
Permalink
Browse files

Disabled exceptions

+ also disabled BOOST exceptions
+ fixed link issue with idbfs.js
  • Loading branch information
gabrielcuvillier committed Dec 3, 2019
1 parent ed144a2 commit 05c80bfff62624fd647ab9c623721564529f60f7
@@ -484,6 +484,9 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
add_definitions(-DBOOST_ALL_NO_LIB)
# We compile with -fno-rtti and boost is not able to detect that for all compilers.
add_definitions(-DBOOST_NO_RTTI -DBOOST_NO_TYPEID)
if (EMSCRIPTEN)
add_definitions(-DBOOST_NO_EXCEPTIONS)
endif()

# GLM: GLM library is stored as git submodule of the current project
# As Arxwasm is not up to date with upstream Arx Libertatis, GLM version 0.9.5.2 have to be used. Later versions introduced some breaking changes.
@@ -1380,7 +1383,7 @@ endif ()

if (EMSCRIPTEN)
add_executable(arxwasm "${ARX_SOURCES}" "${ARX_LIBRARIES}" "${ALL_INCLUDES}")
set_target_properties(arxwasm PROPERTIES COMPILE_FLAGS "-s DISABLE_EXCEPTION_CATCHING=0 -s USE_BOOST_HEADERS=1 -s USE_REGAL=1 -s USE_LIBPNG=1 -s USE_FREETYPE=1 -s USE_ZLIB=1 -s USE_SDL=2")
set_target_properties(arxwasm PROPERTIES COMPILE_FLAGS "-fno-exceptions -fno-rtti -s DISABLE_EXCEPTION_CATCHING=1 -s USE_BOOST_HEADERS=1 -s USE_REGAL=1 -s USE_LIBPNG=1 -s USE_FREETYPE=1 -s USE_ZLIB=1 -s USE_SDL=2")

set(LINK_FLAGS "${LINK_FLAGS} -s USE_REGAL=1 -s USE_LIBPNG=1 -s USE_FREETYPE=1 -s USE_ZLIB=1 -s USE_SDL=2")
set(LINK_FLAGS "${LINK_FLAGS} --shell-file ../data/emscripten/shell.html")
@@ -1395,11 +1398,12 @@ if (EMSCRIPTEN)
# To be replaced by ASYNCIFY_WHITELIST equivalent
#set(LINK_FLAGS "${LINK_FLAGS} -s EMTERPRETIFY_WHITELIST=[\"_main\",\"__ZL8emloopcbv\",\"__ZN7ArxGame14emscripten_runEv\",\"__Z12Menu2_Renderv\",\"__Z15ARX_Menu_Renderv\",\"__ZN7ArxGame6renderEv\",\"__Z13ARX_QuickLoadv\",\"__ZN8MainMenu19onClickedResumeGameEv\",\"__ZN5boost6detail8function26void_function_obj_invoker1INS_3_bi6bind_tIvNS_4_mfi3mf0Iv24ChooseLoadOrSaveMenuPageEENS3_5list1INS3_5valueIPS7_EEEEEEvP10TextWidgetE6invokeERNS1_15function_bufferESG_\",\"__ZN10TextWidget12OnMouseClickEv\",\"__ZN8MainMenu6UpdateEv\",\"__Z13FastSceneLoadRKN3res4pathE\",\"__Z22ARX_CHANGELEVEL_ChangeRKNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES7_l\",\"__Z20ARX_CHANGELEVEL_LoadRKN2fs4pathE\",\"__ZL24ARX_CHANGELEVEL_PopLevellb\",\"__Z12ARX_SlotLoad10HandleTypeI17SavegameHandleTaglLin1EE\",\"__Z9levelInitv\",\"__Z19DANAE_StartNewQuestv\",\"__ZN7ArxGame7doFrameEv\",\"__Z14DanaeLoadLevelRKN3res4pathEb\",\"__Z15LoadLevelScreenv\",\"__Z15LoadLevelScreenl\"]")
set(LINK_FLAGS "${LINK_FLAGS} -s EXIT_RUNTIME=0")
set(LINK_FLAGS "${LINK_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0")
set(LINK_FLAGS "${LINK_FLAGS} -s DISABLE_EXCEPTION_CATCHING=1")
set(LINK_FLAGS "${LINK_FLAGS} -s ENVIRONMENT=web")
set(LINK_FLAGS "${LINK_FLAGS} -lopenal")
set(LINK_FLAGS "${LINK_FLAGS} -legl.js")
set(LINK_FLAGS "${LINK_FLAGS} -lwebgl.js")
set(LINK_FLAGS "${LINK_FLAGS} -lidbfs.js")
set_target_properties(arxwasm PROPERTIES LINK_FLAGS ${LINK_FLAGS})

else ()
@@ -301,16 +301,22 @@ static void enable(util::cmdline::optional<std::string> limit) {
} else if(unit == "h" || unit == "hours" || unit == "hour") {
multiplier = 60 * 60 * 1000;
} else {
#if !defined(__EMSCRIPTEN__)
throw util::cmdline::error(util::cmdline::error::invalid_cmd_syntax,
"unknown unit \"" + unit + "\"");
#endif
}
}
#if !defined(__EMSCRIPTEN__)
try {
#endif
g_timeLimit = multiplier * boost::lexical_cast<float>(*limit);
#if !defined(__EMSCRIPTEN__)
} catch(...) {
throw util::cmdline::error(util::cmdline::error::invalid_cmd_syntax,
"inavlid number \"" + *limit + "\"");
throw util::cmdline::error(util::cmdline::error::invalid_cmd_syntax,
"inavlid number \"" + *limit + "\"");
}
#endif
} else {
g_timeLimit = std::numeric_limits<u64>::max();
}
@@ -47,13 +47,17 @@ EntityId::EntityId(const std::string & id)

m_instance = 0;
if(sep != std::string::npos) {
#if !defined(__EMSCRIPTEN__)
try {
#endif
m_instance = boost::lexical_cast<EntityInstance>(id.c_str() + sep + 1);
#if !defined(__EMSCRIPTEN__)
} catch(...) {
m_className = id;
m_instance = -1;
return;
}
#endif
}

m_className = id.substr(0, sep);
@@ -1208,9 +1208,13 @@ float GetHitValue( const std::string & name) {

if(boost::starts_with(name, "hit_")) {
// Get the number after the first 4 characters in the string
#if !defined(__EMSCRIPTEN__)
try {
#endif
return float(boost::lexical_cast<long>(name.substr(4)));
#if !defined(__EMSCRIPTEN__)
} catch(...) { /* ignore */ }
#endif
}

return -1;
@@ -789,11 +789,15 @@ static void handleRuneDetection(Rune rune) {
void ARX_SPELLS_AnalyseSYMBOL() {

long sm = 0;
#if !defined(__EMSCRIPTEN__)
try {
sm = boost::lexical_cast<long>(SpellMoves);
#endif
sm = boost::lexical_cast<long>(SpellMoves);
#if !defined(__EMSCRIPTEN__)
} catch(...) {
LogDebug("bad spell moves: " << SpellMoves);
}
#endif

switch(sm) {

@@ -911,7 +911,9 @@ const T * fts_read(const char * & data, const char * end, size_t n = 1) {

if(data + toread > end) {
LogDebug(sizeof(T) << " * " << n << " > " << (end - data));
#if !defined(__EMSCRIPTEN__)
throw file_truncated_exception();
#endif
}

const T * result = reinterpret_cast<const T *>(data);
@@ -947,9 +949,10 @@ bool FastSceneLoad(const res::path & partial_path) {

const char * data = NULL, * end = NULL;
boost::scoped_array<char> bytes;


#if !defined(__EMSCRIPTEN__)
try {
#endif
// Load the whole file
LogDebug("Loading " << file);
size_t size;
@@ -1001,19 +1004,24 @@ bool FastSceneLoad(const res::path & partial_path) {
}
progressBarAdvance(3.f);
LoadLevelScreen();

#if !defined(__EMSCRIPTEN__)
} catch(file_truncated_exception) {
LogError << "FTS: truncated file " << file;
return false;
}

#endif

#if !defined(__EMSCRIPTEN__)
try {
#endif
return loadFastScene(file, data, end);
#if !defined(__EMSCRIPTEN__)
} catch(file_truncated_exception) {
LogError << "FTS: truncated compressed data in " << file;
return false;
}
#endif
}


@@ -252,14 +252,18 @@ static Font * createFont(const res::path & fontFace,
arx_assert(fontSize > 0);
arx_assert(scaleFactor > 0.f);
arx_assert(scaleFactor < 1000.f); // TODO better maximum


#if !defined(__EMSCRIPTEN__)
try {
#endif
std::string szFontSize = boost::lexical_cast<std::string>(fontSize);
std::string configSize = getLocalised(configSizeKey, szFontSize);
fontSize = boost::lexical_cast<unsigned int>(configSize);
#if !defined(__EMSCRIPTEN__)
} catch(const boost::bad_lexical_cast &) {
LogError << "Invalid font size for: " << configSizeKey;
}
#endif

fontSize *= scaleFactor;

@@ -566,19 +566,27 @@ InputKeyId Input::getKeyId(const std::string & name) {
}

if(!name.compare(0, PREFIX_KEY.length(), PREFIX_KEY)) {
try {
#if !defined(__EMSCRIPTEN__)
try {
#endif
int key = boost::lexical_cast<int>(name.substr(PREFIX_KEY.length()));
return key;
#if !defined(__EMSCRIPTEN__)
} catch(const boost::bad_lexical_cast &) { }
#endif
}

if(!name.compare(0, PREFIX_BUTTON.length(), PREFIX_BUTTON)) {
try {
#if !defined(__EMSCRIPTEN__)
try {
#endif
int key = boost::lexical_cast<int>(name.substr(PREFIX_BUTTON.length()));
if(key >= 0 && key < Mouse::ButtonCount) {
return Mouse::ButtonBase + key - 1;
}
#if !defined(__EMSCRIPTEN__)
} catch(const boost::bad_lexical_cast &) { }
#endif
}

if(keyNames.empty()) {
@@ -93,7 +93,9 @@ static int bits(state * s, int need) {
while(s->bitcnt < need) {
if(s->left == 0) {
s->left = s->infun(s->inhow, &(s->in));
#if !defined(__EMSCRIPTEN__)
if (s->left == 0) throw blast_truncated_error(); /* out of input */
#endif
}
val |= (int)(*(s->in)++) << s->bitcnt; /* load eight bits */
s->left--;
@@ -177,7 +179,9 @@ static int decode(state * s, huffman * h) {
if(left == 0) break;
if(s->left == 0) {
s->left = s->infun(s->inhow, &(s->in));
#if !defined(__EMSCRIPTEN__)
if (s->left == 0) throw blast_truncated_error(); /* out of input */
#endif
}
bitbuf = *(s->in)++;
s->left--;
@@ -416,11 +420,15 @@ BlastResult blast(blast_in infun, void *inhow, blast_out outfun, void *outhow) {
s.first = 1;

BlastResult err;
try {
#if !defined(__EMSCRIPTEN__)
try{
#endif
err = blastDecompress(&s);
#if !defined(__EMSCRIPTEN__)
} catch(const blast_truncated_error &) {
err = BLAST_TRUNCATED_INPUT;
}
#endif

// write any leftover output and update the error code if needed
if(err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0) {
@@ -45,12 +45,16 @@ int IniKey::getValue(int defaultValue) const {
}

float IniKey::getValue(float defaultValue) const {


#if !defined(__EMSCRIPTEN__)
try {
return boost::lexical_cast<float>(value);
#endif
return boost::lexical_cast<float>(value);
#if !defined(__EMSCRIPTEN__)
} catch(boost::bad_lexical_cast &) {
return defaultValue;
}
#endif
}

bool IniKey::getValue(bool defaultValue) const {
@@ -50,10 +50,12 @@ void * alloc_aligned(std::size_t alignment, std::size_t size) {
}
#else
#error "No aligned memory allocator available!"
#endif
#endif
#if !defined(__EMSCRIPTEN__)
if(!ptr) {
throw std::bad_alloc();
}
#endif
return ptr;
}

@@ -187,7 +187,11 @@ struct aligned_allocator {
pointer allocate(size_type n, std::allocator<void>::const_pointer hint = 0) {
ARX_UNUSED(hint);
if(n > max_size()) {
#if !defined(__EMSCRIPTEN__)
throw std::bad_alloc();
#else
return NULL;
#endif
}
return (pointer)AlignedAllocator<Alignment>::alloc_array(n * sizeof(value_type));
}
@@ -540,11 +540,15 @@ MemoryInfo getMemoryInfo() {
boost::trim(value);

u64 number = 0;
#if !defined(__EMSCRIPTEN__)
try {
number = boost::lexical_cast<u64>(value) * u64(1024);
#endif
number = boost::lexical_cast<u64>(value) * u64(1024);
#if !defined(__EMSCRIPTEN__)
} catch(...) {
continue;
}
#endif

std::string label = line.substr(0, sep);
boost::trim(label);
@@ -58,11 +58,13 @@ ExitStatus parseCommandLine(int argc, char ** argv) {
// Register all program options in the command line interpreter
util::cmdline::interpreter<std::string> cli;
BaseOption::registerAll(cli);


#if !defined(__EMSCRIPTEN__)
try {
#endif

util::cmdline::parse(cli, argc, argv);
#if !defined(__EMSCRIPTEN__)
} catch(util::cmdline::error & e) {

LogCritical << e.what();
@@ -71,6 +73,7 @@ ExitStatus parseCommandLine(int argc, char ** argv) {

return ExitFailure;
}
#endif

return RunProgram;
}
@@ -65,8 +65,9 @@ void parse(interpreter<std::string> & cli, int argc, char ** argv) {

// Parse the option starting athe the current token
std::string option = *p;
#if !defined(__EMSCRIPTEN__)
try {
#endif
const iterator original_p = p;

iterator optend = p + 1; //< end for optional arguments
@@ -136,7 +137,9 @@ void parse(interpreter<std::string> & cli, int argc, char ** argv) {

case LongOption: {
// Argument given for long option that doesn't take arguments
#if !defined(__EMSCRIPTEN__)
throw error(error::invalid_arg_count, "too many arguments");
#endif
}

case ShortOption: {
@@ -148,17 +151,19 @@ void parse(interpreter<std::string> & cli, int argc, char ** argv) {

case PositionalArguments: {
// Unused positional arguments
#if !defined(__EMSCRIPTEN__)
throw error(error::invalid_arg_count, "too many positional arguments");
#endif
}

}
}
#if !defined(__EMSCRIPTEN__)
} catch(error & e) {

std::ostringstream oss;
oss << "Error parsing command-line";

if(option == "--") {
if(p != end) {
oss << " argument \"" << util::escapeString(*p, "\\\" '$!") << "\"";
@@ -175,10 +180,11 @@ void parse(interpreter<std::string> & cli, int argc, char ** argv) {
oss << ": \"" << util::escapeString(*p, "\\\" '$!") << "\"";
}
}

throw error(e.m_code, oss.str());

}
#endif

}

@@ -48,7 +48,9 @@ template <typename SourceType, typename R>
R construct(SourceType & arg , const R * = 0) {

if(arg.empty()) {
#if !defined(__EMSCRIPTEN__)
throw error(error::invalid_arg_count, "not enough arguments");
#endif
}

R ret(arg.template front<R>());

0 comments on commit 05c80bf

Please sign in to comment.
You can’t perform that action at this time.