Prolog code causing Access Violation error in VS2008
Does anyone know why including a term such as:
Code:
t = PL_new_term_ref();
would cause an Unhandled Exception error message:
Code:
0xC0000005: Access violation reading location 0x0000000c.
(Visual Studio 2008)
I have a header file:
Code:
class UserTaskProlog : public ArAction
{
public:
UserTaskProlog( const char* name = " sth " );
~UserTaskProlog( );
AREXPORT virtual ArActionDesired *fire( ArActionDesired currentDesired );
private:
term_t t;
};
and a cpp file:
Code:
UserTaskProlog::UserTaskProlog( const char* name ) : ArAction( name, " sth " )
{
char** argv;
argv[ 0 ] = "libpl.dll";
PL_initialise( 1, argv );
PlCall( "consult( 'myProg.pl' )" );
}
UserTaskProlog::~UserTaskProlog( )
{
}
ArActionDesired *UserTaskProlog::fire( ArActionDesired currentDesired )
{
cout << " something " << endl;
t = PL_new_term_ref( );
}
Without t=PL_new_term_ref() everything works fine, but when I start adding my Prolog code (declarations first, such as t=PL_new_term_ref), I get this Access Violation error message.
I'd appreciate any help.
Thanks,
argv Memory Allocation (updated code)
Could someone please tell me what I am doing wrong that I get this Unhandled Exception error message:
Code:
0xC0000005: Access violation reading location 0x0000000c.
with a green pointer pointing at my first Prolog line (fid_t):
Here is my header file:
Code:
class UserTaskProlog
{
public:
UserTaskProlog( ArRobot* r );
~UserTaskProlog( );
protected:
int cycles;
char* argv[ 1 ];
term_t tf;
term_t tx;
term_t goal_term;
functor_t goal_functor;
ArRobot* robot;
void logTask( );
};
And here is my main code:
Code:
UserTaskProlog::UserTaskProlog( ArRobot* r ) : robot( r ), robotTaskFunc( this, &UserTaskProlog::logTask )
{
cycles = 0;
argv[ 0 ] = "libpl.dll";
argv[ 1 ] = NULL;
PL_initialise( 1, argv );
PlCall( "consult( 'myPrologFile.pl' )" );
robot->addSensorInterpTask( "UserTaskProlog", 50, &robotTaskFunc );
}
UserTaskProlog::~UserTaskProlog( )
{
robot->remSensorInterpTask( &robotTaskFunc );
}
void UserTaskProlog::logTask( )
{
cycles++;
fid_t fid = PL_open_foreign_frame( );
tf = PL_new_term_ref( );
PL_put_integer( tf, 5 );
tx = PL_new_term_ref( );
goal_term = PL_new_term_ref( );
goal_functor = PL_new_functor( PL_new_atom( "factorial" ), 2 );
PL_cons_functor( goal_term, goal_functor, tf, tx );
int fact;
if ( PL_call( goal_term, NULL ) )
{
PL_get_integer( tx, &fact );
cout << fact << endl;
}
PL_discard_foreign_frame( fid );
}
int main( int argc, char** argv )
{
ArRobot robot;
ArArgumentParser argParser( &argc, argv );
UserTaskProlog talk( &robot );
}
Thank you,