Skip to content

Commit e5569ea

Browse files
committed
Merge pull request livecode#3859 from livecodeali/bugfix-16970
[[ Bug 16970 ]] Fix crash when setting screenPixelScale
2 parents 861e889 + 2981dff commit e5569ea

5 files changed

Lines changed: 46 additions & 6 deletions

File tree

docs/notes/bugfix-16970.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Prevent crash when setting the screenPixelScale

engine/src/exec.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,8 @@ static bool MCPropertyParsePointList(MCStringRef p_input, char_t p_delimiter, ui
17921792

17931793
void MCExecFetchProperty(MCExecContext& ctxt, const MCPropertyInfo *prop, void *mark, MCExecValue& r_value)
17941794
{
1795+
MCAssert(prop -> getter != nil);
1796+
17951797
switch(prop -> type)
17961798
{
17971799
case kMCPropertyTypeAny:
@@ -2592,6 +2594,8 @@ void MCExecFetchProperty(MCExecContext& ctxt, const MCPropertyInfo *prop, void *
25922594

25932595
void MCExecStoreProperty(MCExecContext& ctxt, const MCPropertyInfo *prop, void *mark, MCExecValue p_value)
25942596
{
2597+
MCAssert(prop -> setter != nil);
2598+
25952599
switch(prop -> type)
25962600
{
25972601
case kMCPropertyTypeAny:

engine/src/property.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,14 +5430,13 @@ void MCProperty::eval_global_property_ctxt(MCExecContext& ctxt, MCExecValue& r_v
54305430
if (!MCPropertyInfoTableLookup(which, effective, t_info, t_is_array_prop))
54315431
t_info = lookup_mode_property(getmodepropertytable(), which, effective, t_is_array_prop);
54325432

5433-
if (t_info != nil)
5433+
if (t_info != nil && t_info -> getter != nil)
54345434
{
54355435
MCExecFetchProperty(ctxt, t_info, *t_index, r_value);
54365436
return;
54375437
}
54385438

5439-
MCeerror->add(EE_PROPERTY_NOPROP, line, pos);
5440-
ctxt . Throw();
5439+
ctxt . LegacyThrow(EE_PROPERTY_NOPROP);
54415440
}
54425441

54435442
void MCProperty::eval_object_property_ctxt(MCExecContext& ctxt, MCExecValue& r_value)
@@ -5534,14 +5533,13 @@ void MCProperty::set_global_property(MCExecContext& ctxt, MCExecValue p_value)
55345533
if (!MCPropertyInfoTableLookup(which, effective, t_info, t_is_array_prop))
55355534
t_info = lookup_mode_property(getmodepropertytable(), which, effective, t_is_array_prop);
55365535

5537-
if (t_info != nil)
5536+
if (t_info != nil && t_info -> setter != nil)
55385537
{
55395538
MCExecStoreProperty(ctxt, t_info, *t_index, p_value);
55405539
return;
55415540
}
55425541

5543-
MCeerror->add(EE_PROPERTY_CANTSET, line, pos);
5544-
ctxt . Throw();
5542+
ctxt . LegacyThrow(EE_PROPERTY_CANTSET);
55455543
}
55465544

55475545
void MCProperty::set_object_property(MCExecContext& ctxt, MCExecValue p_value)

tests/lcs/_testlib.livecodescript

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ on TestAssertBroken pDescription, pExpectTrue, pReasonBroken
113113
_TestOutput pExpectTrue, pDescription, "TODO", pReasonBroken
114114
end TestAssertBroken
115115

116+
on TestAssertThrow pDescription, pHandler, pTarget, pErrorCode
117+
local tError
118+
try
119+
dispatch pHandler to pTarget
120+
catch tError
121+
end try
122+
123+
TestAssert pDescription, pErrorCode is item 1 of line 1 of tError
124+
end TestAssertThrow
125+
116126
on ErrorDialog executionError, parseError
117127
write executionError & return to stderr
118128
quit 1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
script "CoreEngineGlobalProperties"
2+
/*
3+
Copyright (C) 2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on _TestSetReadOnlyProperty
20+
set the screenPixelScale to 2
21+
end _TestSetReadOnlyProperty
22+
23+
constant kCantSetPropertyCode = 448
24+
on TestSetReadOnlyProperty
25+
TestAssertThrow "setting read-only global property throws", \
26+
"_TestSetReadOnlyProperty", the long id of me, kCantSetPropertyCode
27+
end TestSetReadOnlyProperty

0 commit comments

Comments
 (0)