Fixed several missing JS exception checks.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4556 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2011-05-31 19:09:18 +00:00
parent 575247de09
commit 9c9c2ffed0
6 changed files with 33 additions and 15 deletions

View File

@ -1496,7 +1496,6 @@ static unsigned baseVertexIndexForEdge(GLushort va, GLushort vb, BOOL textured)
_textureFileName = nil;
isTextureImage = NO;
}
}

View File

@ -1876,16 +1876,15 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
// check outside factors
//
aegis_status = [self checkForAegis]; // is a station or something nearby??
//scripting
// scripting
if (!haveExecutedSpawnAction)
{
// When crashing into a boulder, STATUS_LAUNCHING is sometimes skipped on scooping the resulting splinters.
OOEntityStatus status = [self status];
if (script != nil && (status == STATUS_IN_FLIGHT ||
status == STATUS_LAUNCHING||
status == STATUS_LAUNCHING ||
status == STATUS_BEING_SCOOPED ||
(status == STATUS_ACTIVE && self == [UNIVERSE station])
))
@ -5348,11 +5347,11 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context)
// Post MNSR it's also going to be affected by missing subents, and possibly repair status.
// N.B. "fuel_charge_rate" now fully removed, in favour of a dynamic system. -- Kaks 20110429
if (EXPECT(![UNIVERSE strict]))
if (![UNIVERSE strict])
{
if (EXPECT(PLAYER != nil && mass> 0 && mass != [PLAYER baseMass]))
{
rate = calcFuelChargeRate (mass); // post-MNSR fuelPrices will be affected by missing subents. see [self subEntityDied]
rate = calcFuelChargeRate(mass); // post-MNSR fuelPrices will be affected by missing subents. see [self subEntityDied]
}
}
OOLog(@"fuelPrices", @"\"%@\" fuel charge rate: %.2f (mass ratio: %.2f/%.2f)", [self shipDataKey], rate, mass, [PLAYER baseMass]);
@ -6602,9 +6601,11 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
OOShipGroup *myGroup = [self group];
OOShipGroup *otherGroup = [otherShip group];
if ((otherShip == self) || ([self isPolice] && [otherShip isPolice]) || ([self isThargoid] && [otherShip isThargoid]) ||
(myGroup != nil && otherGroup != nil && (myGroup == otherGroup || [otherGroup leader] == self)) ||
([self scanClass] == CLASS_MILITARY && [otherShip scanClass] == CLASS_MILITARY))
if ((otherShip == self) ||
([self isPolice] && [otherShip isPolice]) ||
([self isThargoid] && [otherShip isThargoid]) ||
(myGroup != nil && otherGroup != nil && (myGroup == otherGroup || [otherGroup leader] == self)) ||
([self scanClass] == CLASS_MILITARY && [otherShip scanClass] == CLASS_MILITARY))
{
isFriendly = YES;
}
@ -7573,7 +7574,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
if (victim != nil)
{
ShipEntity *subent = [victim subEntityTakingDamage];
if (subent && [victim isFrangible])
if (subent != nil && [victim isFrangible])
{
// do 1% bleed-through damage...
[victim takeEnergyDamage: 0.01 * weapon_damage from:self becauseOf: parent];

View File

@ -290,7 +290,7 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s
position.y += v1.y * d1;
position.z += v1.z * d1;
}
[ship setPosition: position];
[ship setPosition:position];
if (shipBeacon != nil)
{
@ -299,11 +299,13 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s
// Don't reduce bounty on misjump. Fixes #17992
// - MKW 2011.03.10
if (!_misjump) [ship setBounty:[ship bounty]/2]; // adjust legal status for new system
if (!_misjump) [ship setBounty:[ship bounty]/2]; // adjust legal status for new system
if ([ship cargoFlag] == CARGO_FLAG_FULL_PLENTIFUL)
{
[ship setCargoFlag: CARGO_FLAG_FULL_SCARCE];
}
if (now - ship_arrival_time < 2.0)
{
[ship witchspaceLeavingEffects]; // adds the ship to the universe with effects.
@ -317,8 +319,7 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s
[ship setSpeed: [ship maxFlightSpeed] * 0.25];
[UNIVERSE addEntity:ship]; // AI and status get initialised here
}
// Should probably pass the wormhole, but they have no JS representation
[ship doScriptEvent:OOJSID("shipExitedWormhole") andReactToAIMessage:@"EXITED WITCHSPACE"];

View File

@ -731,6 +731,11 @@ NSString *OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includ
jsval method;
jsval rval;
NSString *result = nil;
jsval exception;
BOOL hadException;
hadException = JS_GetPendingException(context, &exception);
JS_ClearPendingException(context);
if (JS_GetMethodById(context, global, OOJSID("formatCredits"), &fakeRoot, &method))
{
@ -748,6 +753,8 @@ NSString *OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includ
}
}
if (hadException) JS_SetPendingException(context, exception);
OOJSRelinquishContext(context);
if (EXPECT_NOT(result == nil)) result = [NSString stringWithFormat:@"%li", (long)(tenthsOfCredits) / 10];

View File

@ -153,6 +153,7 @@ void OOJSFrameCallbacksInvoke(OOTimeDelta delta)
for (i = 0; i < sCount; i++)
{
JS_CallFunctionValue(context, NULL, sCallbacks[i].callback, 1, &deltaVal, &result);
JS_ReportPendingException(context);
}
OOJSStopTimeLimiter();

View File

@ -124,6 +124,12 @@ static JSFunctionSpec sScriptMethods[] =
{
context = OOJSAcquireContext();
if (JS_IsExceptionPending(context))
{
JS_ClearPendingException(context);
OOLogERR(@"script.javaScript.load.waitingException", @"Prior to loading script %@, there was a pending JavaScript exception, which has been cleared. This is an internal error, please report it.", path);
}
// Set up JS object
if (!problem)
{
@ -201,6 +207,7 @@ static JSFunctionSpec sScriptMethods[] =
// We don't need the script any more - the event handlers hang around as long as the JS object exists.
JS_DestroyScript(context, script);
}
JS_RemoveObjectRoot(context, &scriptObject);
sRunningStack = stackElement.back;
@ -221,6 +228,7 @@ static JSFunctionSpec sScriptMethods[] =
OOLog(@"script.javaScript.load.success", @"Loaded JavaScript: %@ -- %@", [self displayName], description ? description : (NSString *)@"(no description)");
}
OOLogOutdentIf(@"script.javaScript.willLoad");
DESTROY(filePath); // Only used for error reporting during startup.
@ -229,6 +237,7 @@ static JSFunctionSpec sScriptMethods[] =
if (problem)
{
OOLog(@"script.javaScript.load.failed", @"***** Error loading JavaScript script %@ -- %@", path, problem);
JS_ReportPendingException(context);
DESTROY(self);
}