diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 6ecc4c7fb91ed40600bd3dbd5509dce6e662a733..945f3c370cd28481ec5b66d38eb25df5edb6783e 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -2041,7 +2041,15 @@ void LLLiveLSLEditor::loadScriptText(LLVFS *vfs, const LLUUID &uuid, LLAssetType
 
 	mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), TRUE);
 	mScriptEd->makeEditorPristine();
-	mScriptEd->setScriptName(getItem()->getName());
+
+	std::string script_name = DEFAULT_SCRIPT_NAME;
+	const LLInventoryItem* inv_item = getItem();
+
+	if(inv_item)
+	{
+		script_name = inv_item->getName();
+	}
+	mScriptEd->setScriptName(script_name);
 }