Grey's tut #3 problem

edited September 2011 in Help request
Hi people,

I'm trying to play with orx and to do so I started with Gray's tutorial.
In tut number 3 a new function is introduced: GetObjectByName.
It searches for an orxOBJECT with the given name into the current structure.
It does not work.

I've done some debugging to better understand and here's what I've found.

I'm using svn version recompiled with VS2010 Embedded dynamic debug and release.
We're talking about the debug version.

The GetObjectByName function uses orxStructure_GetFirst accessor function to get the element in the structure.
Elements should have orxSTRUCTURE_ID_OBJECT type.

I debugged the orxStructure_GetFirst function and I saw that at the end, when we do pstStructure = pstNode->pstStructure, the value of pstStructure->eID is 0xdefacede.
After that, the _orxStructure_GetPointer is called and it checks if the structure eID matches the wanted one that, in this case, is orxSTRUCTURE_ID_OBJECT (it shoudl be 14 in dec.)
Obviously it does not match.

So I searched where the 0xdefacede value is assigned. That's the value of orxSTRUCTURE_MAGIC_TAG_ACTIVE when we use the DEBUG version of the orx library.
After re-running the debugger I saw that the value is used when creating the strucutre of an object...so we're talking of function orxStructure_Create().
I see it's called from orxObject_Create() function with param orxSTRUCTURE_ID_OBJECT.
In line 435 of orxStructure.c we have:

/* Stores ID with magic number */
pstStructure->eID = (orxSTRUCTURE_ID)(_eStructureID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE);

_eStructureID equals to orxSTRUCTURE_ID_OBJECT.
orxSTRUCTURE_MAGIC_TAG_ACTIVE should equal to 0xdefacede but the resulting pstStructure->eID is 0xdefacede.
It seems that sometimes orxSTRUCTURE_MAGIC_TAG_ACTIVE is 0x0 and sometimes is 0xdefacede.
It's seems that there's some module compiled in RELEASE and some module compiled in DEBUG mode.
That's weird but explains why orxStructure_GetFirst can't find valid objects.

Any suggestions?

Comments

  • edited September 2011
    I was wrong. I re-checked all I said and I was wrong.

    orxSTRUCTURE_MAGIC_TAG_ACTIVE = 0xDEFACED0
    and xored with orxSTRUCTURE_ID_OBJECT (0xE) gives 0xDEFACEDE so it's all right.

    what I've found now is that the produced assembly is different from what I'd expect.
    I'm talking about function _orxStructure_GetPointer.



    /* Updates result */
    pstResult = ((_pStructure != orxNULL) && (((orxSTRUCTURE *)_pStructure)->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE) == _eStructureID) ? (orxSTRUCTURE *)_pStructure : (orxSTRUCTURE *)orxNULL;

    Here's the disassembly:

    ;test if _pStructure is NULL...if NULL jump to negative case
    00FF223E cmp dword ptr [_pStructure],0
    00FF2242 je _orxStructure_GetPointer+39h (0FF2259h)

    ;load the value of the first 32bit field of _pStructure (eID)
    00FF2244 mov eax,dword ptr [_pStructure]
    00FF2247 mov ecx,dword ptr [eax]

    ;WTF? where is the XOR????
    00FF2249 cmp ecx,dword ptr [_eStructureID]

    ; bla bla bla...
    00FF224C jne _orxStructure_GetPointer+39h (0FF2259h)
    00FF224E mov edx,dword ptr [_pStructure]
    00FF2251 mov dword ptr [ebp-0D0h],edx
    00FF2257 jmp _orxStructure_GetPointer+43h (0FF2263h)
    00FF2259 mov dword ptr [ebp-0D0h],0
    00FF2263 mov eax,dword ptr [ebp-0D0h]
    00FF2269 mov dword ptr [pstResult],eax
  • edited September 2011
    As _orxStructure_GetPointer() is compiled by the end project and not in orx's lib, don't forget to define __orxDEBUG__ (with 2 leading and 2 trailing underscores) when compiling your debug version and linking with liborxd.a / orxd.lib.
    Everytime that error (or a similar one) happens it's due to a version mismatch (ie. defining __orxDEBUG__ and linking with a release version of orx or vice versa).
    If, after you've checked your defines and versions, you still have the issue, please let me know!
  • edited September 2011
    Doh! It works! :laugh:
    Thank you man!
  • edited September 2011
    No worries. Been there, done that! ;)
Sign In or Register to comment.