mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-29 07:37:45 +00:00
remove exceptions and handle error cases inside initMesh
This commit is contained in:
parent
babd47d772
commit
0234800fce
3 changed files with 27 additions and 13 deletions
|
@ -36,7 +36,8 @@ bool Sapphire::World::Navi::NaviProvider::init()
|
||||||
{
|
{
|
||||||
auto baseMesh = meshFolder / std::experimental::filesystem::path( m_internalName + ".nav" );
|
auto baseMesh = meshFolder / std::experimental::filesystem::path( m_internalName + ".nav" );
|
||||||
|
|
||||||
loadMesh( baseMesh.string() );
|
if( !loadMesh( baseMesh.string() ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
initQuery();
|
initQuery();
|
||||||
|
|
||||||
|
@ -376,11 +377,14 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 >
|
||||||
return resultCoords;
|
return resultCoords;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
bool Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
||||||
{
|
{
|
||||||
FILE* fp = fopen( path.c_str(), "rb" );
|
FILE* fp = fopen( path.c_str(), "rb" );
|
||||||
if( !fp )
|
if( !fp )
|
||||||
throw std::runtime_error( "Could open navimesh file" );
|
{
|
||||||
|
Logger::error( "Couldn't open navimesh file: {0}", path );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Read header.
|
// Read header.
|
||||||
NavMeshSetHeader header;
|
NavMeshSetHeader header;
|
||||||
|
@ -389,19 +393,22 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
||||||
if( readLen != 1 )
|
if( readLen != 1 )
|
||||||
{
|
{
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Could not read NavMeshSetHeader" );
|
Logger::error( "Couldn't read NavMeshSetHeader for {0}", path );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( header.magic != NAVMESHSET_MAGIC )
|
if( header.magic != NAVMESHSET_MAGIC )
|
||||||
{
|
{
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Not a NavMeshSet" );
|
Logger::error( "'{0}' has an incorrect NavMeshSet header.", path );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( header.version != NAVMESHSET_VERSION )
|
if( header.version != NAVMESHSET_VERSION )
|
||||||
{
|
{
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Invalid NavMeshSet version" );
|
Logger::error( "'{0}' has an incorrect NavMeshSet version. Expected '{1}', got '{2}'", path, NAVMESHSET_VERSION, header.version );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !m_naviMesh )
|
if( !m_naviMesh )
|
||||||
|
@ -410,14 +417,16 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
||||||
if( !m_naviMesh )
|
if( !m_naviMesh )
|
||||||
{
|
{
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Could not allocate dtNavMesh" );
|
Logger::error( "Couldn't allocate dtNavMesh" );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dtStatus status = m_naviMesh->init( &header.params );
|
dtStatus status = m_naviMesh->init( &header.params );
|
||||||
if( dtStatusFailed( status ) )
|
if( dtStatusFailed( status ) )
|
||||||
{
|
{
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Could not initialize dtNavMesh" );
|
Logger::error( "Couldn't initialise dtNavMesh" );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,13 +438,14 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
||||||
if( readLen != 1 )
|
if( readLen != 1 )
|
||||||
{
|
{
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Could not read NavMeshTileHeader" );
|
Logger::error( "Couldn't read NavMeshTileHeader from '{0}'", path );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !tileHeader.tileRef || !tileHeader.dataSize )
|
if( !tileHeader.tileRef || !tileHeader.dataSize )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
uint8_t* data = reinterpret_cast< uint8_t* >( dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM ) );
|
auto data = reinterpret_cast< uint8_t* >( dtAlloc( tileHeader.dataSize, DT_ALLOC_PERM ) );
|
||||||
if( !data )
|
if( !data )
|
||||||
break;
|
break;
|
||||||
memset( data, 0, tileHeader.dataSize );
|
memset( data, 0, tileHeader.dataSize );
|
||||||
|
@ -444,11 +454,15 @@ void Sapphire::World::Navi::NaviProvider::loadMesh( const std::string& path )
|
||||||
{
|
{
|
||||||
dtFree( data );
|
dtFree( data );
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
throw std::runtime_error( "Could not read tile data" );
|
|
||||||
|
Logger::error( "Couldn't read tile data from '{0}'", path );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_naviMesh->addTile( data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0 );
|
m_naviMesh->addTile( data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace Sapphire::World::Navi
|
||||||
explicit NaviProvider( const std::string& internalName, FrameworkPtr pFw );
|
explicit NaviProvider( const std::string& internalName, FrameworkPtr pFw );
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
void loadMesh( const std::string& path );
|
bool loadMesh( const std::string& path );
|
||||||
void initQuery();
|
void initQuery();
|
||||||
|
|
||||||
void toDetourPos( const Common::FFXIVARR_POSITION3& position, float* out );
|
void toDetourPos( const Common::FFXIVARR_POSITION3& position, float* out );
|
||||||
|
|
|
@ -53,7 +53,7 @@ bool Sapphire::Scripting::ScriptMgr::init()
|
||||||
|
|
||||||
if( !status )
|
if( !status )
|
||||||
{
|
{
|
||||||
Logger::error( "ScriptMgr: failed to load scripts, the server will not function correctly without scripts loaded." );
|
Logger::error( "ScriptMgr: failed to load modules, the server will not function correctly without scripts loaded." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue