Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash when setting label text on a game object with multiple labels #8580

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions engine/gamesys/src/gamesys/scripts/script_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ static int SetText(lua_State* L)

dmGameObject::HInstance instance = CheckGoInstance(L);

dmMessage::URL receiver;
dmMessage::URL sender;
dmScript::GetURL(L, &sender);
dmScript::ResolveURL(L, 1, &receiver, &sender);
// issue-8555: check that the url is targeting a specific component and not only a path
if (receiver.m_Fragment == 0)
{
return DM_LUA_ERROR("Expected url to specify a component, not only a path!");
}

size_t text_len = 0;
const char* text = luaL_checklstring(L, 2, &text_len);
if (!text)
Expand All @@ -298,11 +308,6 @@ static int SetText(lua_State* L)
message->m_Text = (const char*)sizeof(dmGameSystemDDF::SetText);
memcpy((void*)(data + sizeof(dmGameSystemDDF::SetText)), text, text_len + 1);

dmMessage::URL receiver;
dmMessage::URL sender;
dmScript::GetURL(L, &sender);
dmScript::ResolveURL(L, 1, &receiver, &sender);

if (dmMessage::RESULT_OK != dmMessage::Post(&sender, &receiver, dmGameSystemDDF::SetText::m_DDFDescriptor->m_NameHash, (uintptr_t)instance, (uintptr_t)dmGameSystemDDF::SetText::m_DDFDescriptor, data, data_size, 0) )
{
return DM_LUA_ERROR("Failed to send label string as message!");
Expand Down