diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 4bb247f94..04ac21890 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -361,16 +361,20 @@ static void FinishThingdef() if (sfunc == NULL) { FCompileContext ctx(ti); - dmg->Resolve(ctx); - VMFunctionBuilder buildit; - buildit.Registers[REGT_POINTER].Get(1); // The self pointer - dmg->Emit(&buildit); - sfunc = buildit.MakeFunction(); - sfunc->NumArgs = 1; - sfunc->Proto = NULL; ///FIXME: Need a proper prototype here - // Save this function in case this damage value was reused - // (which happens quite easily with inheritance). - dmg->SetFunction(sfunc); + dmg = static_cast(dmg->Resolve(ctx)); + + if (dmg != nullptr) + { + VMFunctionBuilder buildit; + buildit.Registers[REGT_POINTER].Get(1); // The self pointer + dmg->Emit(&buildit); + sfunc = buildit.MakeFunction(); + sfunc->NumArgs = 1; + sfunc->Proto = NULL; ///FIXME: Need a proper prototype here + // Save this function in case this damage value was reused + // (which happens quite easily with inheritance). + dmg->SetFunction(sfunc); + } } def->Damage = sfunc; diff --git a/src/thingdef/thingdef_parse.cpp b/src/thingdef/thingdef_parse.cpp index f4bad69bb..566643b8e 100644 --- a/src/thingdef/thingdef_parse.cpp +++ b/src/thingdef/thingdef_parse.cpp @@ -191,7 +191,12 @@ static void ParseConstant (FScanner &sc, PSymbolTable *symt, PClassActor *cls) FxExpression *expr = ParseExpression (sc, cls, true); sc.MustGetToken(';'); - if (!expr->isConstant()) + if (expr == nullptr) + { + sc.ScriptMessage("Error while resolving constant definition"); + FScriptPosition::ErrorCounter++; + } + else if (!expr->isConstant()) { sc.ScriptMessage("Constant definition is not a constant"); FScriptPosition::ErrorCounter++; @@ -247,16 +252,24 @@ static void ParseEnum (FScanner &sc, PSymbolTable *symt, PClassActor *cls) if (sc.CheckToken('=')) { FxExpression *expr = ParseExpression (sc, cls, true); - if (!expr->isConstant()) + if (expr != nullptr) { - sc.ScriptMessage("'%s' must be constant", symname.GetChars()); - FScriptPosition::ErrorCounter++; + if (!expr->isConstant()) + { + sc.ScriptMessage("'%s' must be constant", symname.GetChars()); + FScriptPosition::ErrorCounter++; + } + else + { + currvalue = static_cast(expr)->GetValue().GetInt(); + } + delete expr; } else { - currvalue = static_cast(expr)->GetValue().GetInt(); + sc.ScriptMessage("Error while resolving expression of '%s'", symname.GetChars()); + FScriptPosition::ErrorCounter++; } - delete expr; } PSymbolConstNumeric *sym = new PSymbolConstNumeric(symname, TypeSInt32); sym->Value = currvalue; @@ -568,7 +581,13 @@ static void ParseUserVariable (FScanner &sc, PSymbolTable *symt, PClassActor *cl if (sc.CheckToken('[')) { FxExpression *expr = ParseExpression(sc, cls, true); - if (!expr->isConstant()) + if (expr == nullptr) + { + sc.ScriptMessage("Error while resolving array size"); + FScriptPosition::ErrorCounter++; + maxelems = 1; + } + else if (!expr->isConstant()) { sc.ScriptMessage("Array size must be a constant"); FScriptPosition::ErrorCounter++;