Check whether intent data is set before accessing

This commit is contained in:
Marijn van der Werf 2017-09-23 23:17:32 +02:00
parent efa87bf931
commit 8a47308786
1 changed files with 20 additions and 0 deletions

View File

@ -57,6 +57,11 @@ rct_windowclass Intent::GetWindowClass()
void * Intent::GetPointerExtra(uint32 key)
{
if (_Data.count(key) == 0)
{
return nullptr;
}
auto data = _Data.at(key);
openrct2_assert(data.type == IntentData::DT_POINTER, "Actual type doesn't match requested type");
return (void *) data.pointerVal;
@ -64,6 +69,11 @@ void * Intent::GetPointerExtra(uint32 key)
uint32 Intent::GetUIntExtra(uint32 key)
{
if (_Data.count(key) == 0)
{
return 0;
}
auto data = _Data.at(key);
openrct2_assert(data.type == IntentData::DT_UINT, "Actual type doesn't match requested type");
return data.uintVal;
@ -71,6 +81,11 @@ uint32 Intent::GetUIntExtra(uint32 key)
sint32 Intent::GetSIntExtra(uint32 key)
{
if (_Data.count(key) == 0)
{
return 0;
}
auto data = _Data.at(key);
openrct2_assert(data.type == IntentData::DT_SINT, "Actual type doesn't match requested type");
return data.sintVal;
@ -78,6 +93,11 @@ sint32 Intent::GetSIntExtra(uint32 key)
utf8string Intent::GetStringExtra(uint32 key)
{
if (_Data.count(key) == 0)
{
return nullptr;
}
auto data = _Data.at(key);
openrct2_assert(data.type == IntentData::DT_STRING, "Actual type doesn't match requested type");
return data.stringVal;