OpenClonk Bugtracker - OpenClonk
View Issue Details
0001904OpenClonkEnginepublic2017-04-11 15:312017-04-19 07:49
ReporterIsilkor 
Assigned ToIsilkor 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001904: Sort_Speed is completely broken
DescriptionAdding Sort_Speed as a sorting criterion in FindObjects does nothing useful and returns the objects in arbitrary order.
Steps To Reproducevar a = [];
for (var i = 0; i < 10; ++i)
{
    a[i] = CreateObjectAbove(Dummy, 100, 100, NO_OWNER);
    // Use Cos for fake random velocities in the absence of a way to
    // manually seed the PRNG
    a[i]->SetXDir(Abs(Cos(i * 66, 100)));
}

for (var o in FindObjects(Find_ID(Dummy), Sort_Speed()))
    Log("%v: %d", o, o->GetXDir());

/*
Expected result:
Object(5): 10
Object(8): 21
Object(2): 41
Object(10): 59
Object(3): 67
Object(7): 81
Object(6): 87
Object(4): 95
Object(9): 98
Object(1): 100
****
Actual result:
Object(10): 59
Object(9): 98
Object(8): 21
Object(7): 81
Object(6): 87
Object(5): 10
Object(4): 95
Object(3): 67
Object(2): 41
Object(1): 100
*/
TagsNo tags attached.
Attached Files

Notes
(0005648)
Isilkor   
2017-04-11 16:56   
Reason is a non-explicit operator bool inside C4Fixed, which gets used for implicit conversion to int. C4SortObjectSpeed::CompareGetValue should use fixtoi instead.
(0005657)
occ   
2017-04-19 07:49   
Hi! There's been a check-in that references this bug. For more information you can visit the repository browser at this address:
https://git.openclonk.org/openclonk.git/commitdiff/81e49fe0f583798464a14085b106c266bfb12f35

Changeset 81e49fe by Nicolas Hake <isilkor@openclonk.org>
Fix several broken conversions from C4Fixed->bool->int (0001904)

This is why non-explicit operator bool is bad.


Issue History
2017-04-11 15:31IsilkorNew Issue
2017-04-11 16:56IsilkorNote Added: 0005648
2017-04-19 07:49occNote Added: 0005657
2017-04-19 07:49IsilkorAssigned To => Isilkor
2017-04-19 07:49IsilkorStatusnew => resolved
2017-04-19 07:49IsilkorResolutionopen => fixed