64bit issue(S): SORTARRAY (fixed)

Previous topic - Next topic

spacefractal

SORTARRAY is still not working correctly when used with objects, which is used on my last game, Karma Miwa.

Its crash in glb.h:
Code (glbasic) Select

template <class T> DGPtr compare_by_foo(T& a, T& b, DGPtr foo)
{
typedef DGPtr(*pcmp)(T&a, T&b);
pcmp cmp;
#pragma warning(disable:4312)
cmp = (pcmp)(DGPtr*)foo;
return (DGPtr)cmp(a,b); // Its crash here with a adresss error.
}


PS. Damn only this post got splitted. Sorry. Im would like to split the rest, so its dosent got debated in the general thread. sorry.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

#1
im got a bit messed when im tried to split the post with that and the follow posts after that (there is only 2), because im wanted the SORTARRAY issue on its own post.

Im really Sorry about it. Its a mistake by me.

Here is the answear after that:
http://www.glbasic.com/forum/index.php?topic=10082.msg89752#msg89752

But please keep the SORTARRAY issue here:






tried:
Code (glbasic) Select

template <class T> int compare_by_foo(T& a, T& b, DGPtr foo)
{
typedef int(*pcmp)(T&a, T&b);
pcmp cmp;
cmp = (pcmp)(void*)foo;
return (int)cmp(a,b);
}

template <class T> void SORTARRAY(T& arry, DGPtr foo)
{
int len = LEN(arry);
if(len>1)
sortarray(&arry(0), &arry(len-1), foo);
}


Code (glbasic) Select

DGInt compare(Object& a, Object& b)
{   __PPRegisterFunction
if (a.obid<b.obid )
return -1;
if (a.obid>b.obid )
return 1;
return 0;
}


on if (a.obid>b.obid

Im gonna thinks its more a bug in class DGArray when used as objects in glb.h?


Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

So the compare function is defined by :

Code (glbasic) Select
    template <class T> int compare_by_foo(T& a, T& b, INT_PTR foo)
    {
        typedef int(*pcmp)(T&a, T&b);
        pcmp cmp;
//       #pragma warning(disable:4312)
        cmp = (pcmp)(void*)foo;
        return (int)cmp(a,b);
    }


My routine is this :

Code (glbasic) Select
DGNat routine(DGNat &a, DGNat &b)
{
DEBUG("A:"); DEBUG(FORMAT_Str(0, 0, a)); DEBUG("\n");
DEBUG("B:"); DEBUG(FORMAT_Str(0, 0, b)); DEBUG("\n");
return (a<b ? -1 : \
a>b ? 1 : 0);
}


I call it with this :

Code (glbasic) Select
typedef int(*pcmp)(DGNat &a, DGNat &b);
void *cmp;
//pcmp cmp;
//       #pragma warning(disable:4312)
//cmp = (pcmp)(void*)routine;
cmp = routine;

DGArray<DGNat> temp;

DIM(temp, 10);
temp(0) = 4;
temp(1) = 14;
temp(2) = 5;
temp(3) = 3;
temp(4) = -1;
temp(5) = 89;
temp(6) = 12;
temp(7) = 123;
temp(8) = 0;
temp(9) = 0;
SORTARRAY(temp, (DGNat) cmp);

for (DGNat loop = 0; loop < BOUNDS(temp, 0); loop++)
{
DEBUG(FORMAT_Str(0,0,temp(loop)) + "\n");
}
KEYWAIT();



spacefractal

#3
this is something that is abit out of ths scope how its works. Since HeadKaze is a experimenede c++ and even uses xcode for codning directly, its property easier what he does. Its was him that let me go so far im got 3 out of the 4 games compiled.

btw im do not hope its the compare function its self that is buggy, which means im cant fix that by my self at all, due its a bug in that way glbasic generate the cpp files.

Im believe SORTARRAY works with normal string and numbers (its diddent crash when called internal like in the file sorting), but its does crash when Arrays with a object using TYPE is used.

So the bug can been a diffent kind of issue than excepted me things. Just like the very first crash bug (which crashed on a line, which wasent a bug there, but the bug its self was in a complete different h file).
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

Please Note DEBUG is deprecated for iOS. This due its allready a taken namespace and defined by Apple, so that have to been removed now.

But internal, DEBUG could been compiled something like DEBUG_Str() or something like that. But im would do better perfer STDOUT(), which is much more compatible to uses for all platforms.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

Will you be changing it for all platforms ?

spacefractal

By now only for ios, which I'm have defined it out.the best next thing is rename it internal under compiling.

But STDOUT and DEBUG is pretty much the same thing.

I'm have allways used DEBUG for windows only.

I'm so believe it's a pointer issue somewhere. The game do works nice in 32bit mode. It's the last game remaining. Property the only bug left.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

This issue have just been fixed.

But there is confuction about this in the manual.

in the code example:
Code (glbasic) Select

FUNCTION compare: BYREF a, BYREF b
   IF a<b THEN RETURN -1
   IF a>b THEN RETURN 1
   RETURN 0
ENDFUNCTION


FUNCTION inverse_compare: BYREF a, BYREF b
   IF a<b THEN RETURN 1
   IF a>b THEN RETURN -1
   RETURN 0
ENDFUNCTION


would NOT work in 64bit mode, because its will returns a float, not a int.

its needs to been changed to (to make sure its returns a DGNat, not a DGInt):
Code (glbasic) Select

FUNCTION compare%: BYREF a, BYREF b
   IF a<b THEN RETURN -1
   IF a>b THEN RETURN 1
   RETURN 0
ENDFUNCTION


FUNCTION inverse_compare%: BYREF a, BYREF b
   IF a<b THEN RETURN 1
   IF a>b THEN RETURN -1
   RETURN 0
ENDFUNCTION


in the template in glb.h, this one compiled for 64bit:
Code (glbasic) Select

template <class T> int compare_by_foo(T& a, T& b, DGPtr foo)
{
typedef int(*pcmp)(T&a, T&b);
pcmp cmp;
#pragma warning(disable:4312)
cmp = (pcmp)foo;
return cmp(a,b);
}


also make sure foo is a DGPtr in glb.h of course in all instance.

PS. IM move this issue to the bug section.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/