1
0
forked from 0ad/0ad

Correct uncaught MapReader and MapGenerator throw statements following 2b138f47db and 2180862d40.

Differential Revision: https://code.wildfiregames.com/D2089
Reviewed By: historic_bruno
This was SVN commit r22521.
This commit is contained in:
elexis 2019-07-21 01:35:39 +00:00
parent 41ee485e68
commit 51419d7092
3 changed files with 20 additions and 9 deletions

View File

@ -1713,7 +1713,7 @@ function getFilteredMaps(filterFunc)
let file = g_GameAttributes.mapPath + mapFile;
let mapData = loadMapData(file);
if (!mapData.settings || filterFunc && !filterFunc(mapData.settings.Keywords || []))
if (!mapData || !mapData.settings || filterFunc && !filterFunc(mapData.settings.Keywords || []))
continue;
maps.push({

View File

@ -334,14 +334,28 @@ JS::Value CMapGeneratorWorker::LoadHeightmap(ScriptInterface::CxPrivate* pCxPriv
// See CMapReader::UnpackTerrain, CMapReader::ParseTerrain for the reordering
JS::Value CMapGeneratorWorker::LoadMapTerrain(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& filename)
{
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData);
JSContext* cx = self->m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);
if (!VfsFileExists(filename))
throw PSERROR_File_OpenFailed();
{
self->m_ScriptInterface->ReportError(
("Terrain file \"" + filename.string8() + "\" does not exist!").c_str());
return JS::UndefinedValue();
}
CFileUnpacker unpacker;
unpacker.Read(filename, "PSMP");
if (unpacker.GetVersion() < CMapIO::FILE_READ_VERSION)
throw PSERROR_File_InvalidVersion();
{
self->m_ScriptInterface->ReportError(
("Could not load terrain file \"" + filename.string8() + "\" too old version!").c_str());
return JS::UndefinedValue();
}
// unpack size
ssize_t patchesPerSide = (ssize_t)unpacker.UnpackSize();
@ -384,9 +398,6 @@ JS::Value CMapGeneratorWorker::LoadMapTerrain(ScriptInterface::CxPrivate* pCxPri
}
}
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData);
JSContext* cx = self->m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);
JS::RootedValue returnValue(cx, JS::ObjectValue(*JS_NewPlainObject(cx)));
self->m_ScriptInterface->SetProperty(returnValue, "height", heightmap);
self->m_ScriptInterface->SetProperty(returnValue, "textureNames", textureNames);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2017 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -102,7 +102,7 @@ void CMapReader::LoadMap(const VfsPath& pathname, JSRuntime* rt, JS::HandleValu
// check oldest supported version
if (file_format_version < FILE_READ_VERSION)
throw PSERROR_File_InvalidVersion();
throw PSERROR_Game_World_MapLoadFailed("Could not load terrain file - too old version!");
// delete all existing entities
if (pSimulation2)
@ -451,7 +451,7 @@ void CXMLReader::Init(const VfsPath& xml_filename)
node_idx = entity_idx = 0;
if (xmb_file.Load(g_VFS, xml_filename, "scenario") != PSRETURN_OK)
throw PSERROR_File_ReadFailed();
throw PSERROR_Game_World_MapLoadFailed("Could not read map XML file!");
// define the elements and attributes that are frequently used in the XML file,
// so we don't need to do lots of string construction and comparison when