Menu

#63 Minor stack corruption when referencing a nonexistant function

None
closed
nobody
None
5
2014-04-24
2014-04-23
Aerizeon
No

This is a bit of a specific issue:

Whenever a SQRat Function object is constructed referencing a nonexistent squirrel function, Any calls to valid functions no longer work IF they pass a native object as a parameter.

This does not throw any exeptions, And it only throws an internal squirrel error when the native function is called.

C++:

HSQUIRRELVM SquirrelVM = sq_open(2048);
sq_setprintfunc(SquirrelVM, SquirrelOutputHandler, NULL);
sq_newclosure(SquirrelVM, SquirrelRuntimeError, 0);
sq_seterrorhandler(SquirrelVM);
DefaultVM::Set(SquirrelVM);
RootTable().Bind("Point2D",Class<Point2D>()
                  .Var("X", &Point2D::X)
                  .Var("Y", &Point2D::Y));
try
{
Script* Main = new Script();
Main->CompileFile("test.sq");
Main->Run();
//Registers a function that accepts a native object
Function NativeType(RootTable(), "NativeType");
//Registers a function that accepts a basic type
Function SimpleType(RootTable(), "SimpleType");
//Tries to register a nonexistant function - this corrupts the later function calls
//If you remove this, everything works perfectly.
Function Nothing(RootTable(), "Nothing");
Point2D X;
float Y = 10;
//Simple type works fine - Prints the expected output
SimpleType(Y);
//Throws an error in squirrel ("Function not found in slot")
NativeType(X);
//Still works - prints expected output 
SimpleType(Y);
}
catch(exception e)
{
    cout << e.what() << endl;
}

Squirrel:

function NativeType(input)
{
    print("Value:")
    print(input.X)
    print("End");
}

function SimpleType(input)
{
    print("Value:");
    print(input);
    print("End");
}

Output:

Value:
10
End
Value:
Error: Function not found in slot
Value:
10
End

Discussion

  • Wizzard

    Wizzard - 2014-04-23

    The latest version of Sqrat no longer throws exceptions. Instead, there are functions that are documented such that you must check their errors using Sqrat::Error::Occurred. This was done because of a bug with type checking and throwing exceptions. There was one such case where either the API needed to be rewritten or another way of throwing an error had to exist in order to fix a bug. The later was chosen. It was even later decided that Sqrat should only use one type of error checking instead of mixing exceptions and Sqrat::Error::Occurred together.

     

    Last edit: Wizzard 2014-04-23
  • Aerizeon

    Aerizeon - 2014-04-24

    If I disable error checking with the define, would this issue go away? Or should I always check for an error regardless of whether it's enabled (at least, for that function)

     
  • Wizzard

    Wizzard - 2014-04-24

    Disabling error checking implies that the error will never happen because your Squirrel code is flawless

     
  • Aerizeon

    Aerizeon - 2014-04-24

    I apologize, that was a very poorly thought out question.
    Thank you for taking the time to answer this - I hadn't noticed the change in error handling, so this can be closed as wontfix.

     

    Last edit: Aerizeon 2014-04-24
  • Wizzard

    Wizzard - 2014-04-24

    That's no problem! It is an annoying change, and I wish there was a better way to have done it. Good luck with your program!

     
  • Wizzard

    Wizzard - 2014-04-24
    • status: open --> closed
    • Group: -->
     

Log in to post a comment.

MongoDB Logo MongoDB