diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp
index 90fbcfe68..57b554e25 100644
--- a/src/scripting/codegeneration/codegen.cpp
+++ b/src/scripting/codegeneration/codegen.cpp
@@ -8964,7 +8964,7 @@ ExpEmit FxIfStatement::Emit(VMFunctionBuilder *build)
 	}
 	if (WhenFalse != nullptr)
 	{
-		if (!WhenTrue->CheckReturn()) jumpspot = build->Emit(OP_JMP, 0);	// no need to emit a jump if the block returns.
+		if (WhenTrue != nullptr && !WhenTrue->CheckReturn()) jumpspot = build->Emit(OP_JMP, 0);	// no need to emit a jump if the block returns.
 		build->BackpatchListToHere(no);
 		WhenFalse->EmitStatement(build);
 		if (jumpspot != ~0u) build->BackpatchToHere(jumpspot);