Game Development Community

Bug in t2dSceneObject moveTo method

by David House · in Torque Game Builder · 12/04/2005 (6:25 am) · 2 replies

If you don't pass in the last parameter ( targetMargin ), the engine will crash. Looking at the code, the problem appears to be with this section:

// Fetch AutoStop Flag.
    bool autoStop = true;
    if ( argc >= 4 ) autoStop = dAtob(argv[4]);

    // Fetch Callback Flag.
    bool callback = false;
    if ( argc >= 5 ) callback = dAtob(argv[5]);

    // Fetch Snap.
    bool snap = true;
    if ( argc >= 6 ) snap = dAtob(argv[6]);

    // Fetch Target Margin.
    F32 targetMargin = 0.1f;
    if ( argc >= 7 ) targetMargin = dAtof(argv[7]);

The way you are checking the number of arguments isn't really accurate. In the case of Target Margin, the number of arguments will be 8, not 7. If it is 7, then the caller has left off the target margin, but your code will still try to get it at position 7. Crashola... :)

Dang C++ and those zero based arrays... :)

#1
12/04/2005 (10:52 am)
Yeah, thanks David, started-off with the wrong number. Almost every T2D function works this way and sometimes you slip-up!

SDK Updated to:

// Fetch AutoStop Flag.
    bool autoStop = true;
    if ( argc >= 5 ) autoStop = dAtob(argv[4]);

    // Fetch Callback Flag.
    bool callback = false;
    if ( argc >= 6 ) callback = dAtob(argv[5]);

    // Fetch Snap.
    bool snap = true;
    if ( argc >= 7 ) snap = dAtob(argv[6]);

    // Fetch Target Margin.
    F32 targetMargin = 0.1f;
    if ( argc >= 8 ) targetMargin = dAtof(argv[7]);

- Melv.
#2
12/05/2005 (2:56 am)
Just thought I'd mention that this problem existed in the "rotateTo()" function as well. Guess I was having a bad day that day!

Amended the "rotateTo()" function to be:

// Fetch AutoStop Flag.
    bool autoStop = true;
    if ( argc >= 5 ) autoStop = dAtob(argv[4]);

    // Fetch Callback Flag.
    bool callback = false;
    if ( argc >= 6 ) callback = dAtob(argv[5]);

    // Fetch Snap.
    bool snap = true;
    if ( argc >= 7 ) snap = dAtob(argv[6]);

    // Fetch Target Margin.
    F32 targetMargin = 0.1f;
    if ( argc >= 8 ) targetMargin = dAtof(argv[7]);

- Melv.