Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Null pointer returned from constructor?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 justin12343   Members   -  Reputation: 198

Like
0Likes
Like

Posted 02 August 2013 - 07:22 PM

This code that used to work in the previous version of AngelScript now returns a null pointer since updating to version 2.27.0. It's pretty much identical to what's in the manual, so I'm wondering if the method for getting the object pointer has changed since the update.

void Object::CallConstructor()
{
	if (constructorCalled)
		return;

	asIScriptContext *context = scriptManager->GetContext();

	if (context == NULL)
		return;

	if (context->Prepare( funcConstructor) < 0)
	{
		printf( "There was an error preparing the context.\n");
		return;
	}

	*((Object**)context->GetAddressOfArg(0)) = this;
	//AddRef();

	int r = context->Execute();

	if (r != asEXECUTION_FINISHED)
	{
		if (r == asEXECUTION_EXCEPTION)
		{
			const char *exception = context->GetExceptionString();
			printf( "An Exception, '%s', Occurred In The Constructor.\n", exception);
			return;
		}

		if (r == asERROR)
		{
			printf( "An Unexpected Error Occurred In The Constructor.\n");
			return;
		}
	}
	else
	{
		pScrObj = *((asIScriptObject**)context->GetAddressOfReturnValue());// <---------------------
		pScrObj->AddRef(); //Must Be Called or else Pure Virtual Error!
		
		context->Unprepare();
		constructorCalled = true;
	}
}


Sponsor:

#2 justin12343   Members   -  Reputation: 198

Like
0Likes
Like

Posted 02 August 2013 - 08:48 PM

Nevermind, the code is fine. The JIT compiler from Blind Mind Studios does not support the new version of AngelScript. I'll just have to wait until it is updated.



#3 Andreas Jonsson   Moderators   -  Reputation: 3264

Like
0Likes
Like

Posted 05 August 2013 - 10:39 AM

Any idea what is wrong with Blind Mind's JIT compiler? I don't recall making any changes to the bytecode that should break the the JIT compiler, though you will need to recompile the JIT compiler for the new AngelScript interface.

 

Have you contacted Blind Mind about the problem already? ThyReaper here on the forum is their lead develeper. .


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#4 justin12343   Members   -  Reputation: 198

Like
0Likes
Like

Posted 07 August 2013 - 06:27 PM

Any idea what is wrong with Blind Mind's JIT compiler? I don't recall making any changes to the bytecode that should break the the JIT compiler, though you will need to recompile the JIT compiler for the new AngelScript interface.

 

Have you contacted Blind Mind about the problem already? ThyReaper here on the forum is their lead develeper. .

 

I have the jit source files integrated directly into my Visual Studio project so I recompile after updates anyways. I'm not familiar with AngelScript's internals but the problem maybe linked to the object register, since asCContext::GetAddressOfReturnValue() returns a null pointer from it. I've submitted a issue on the Git repository.


Edited by justin12343, 07 August 2013 - 06:31 PM.


#5 justin12343   Members   -  Reputation: 198

Like
0Likes
Like

Posted 16 September 2013 - 03:24 AM

 I've decided to take a second look at this problem since I upgraded to 2.27.1 and there seems to be another issue with compiling. This will mostly be a re-post of what I submitted on the JIT's git repo:

 

The jit seems to not compile any scripts in version 2.27.1 for me at this point that contain classes. This is the very first script that is compiled in my engine:

shared class Base_Object
{
//========== Constructor / Destructor ===========
Base_Object( Object @obj)
{
@this.object = obj;
x = object.x;
y = object.y;
sprite_index = -1;
mask_index = sprite_index;
image_index = object.image_index;
depth = object.depth;
}

//=========== Events =============
void Create(){}
void Destroy(){}
void Alarm1(){}
void Alarm2(){}
void Alarm3(){}
void Alarm4(){}
void Alarm5(){}
void Alarm6(){}
void Alarm7(){}
void Alarm8(){}
void Alarm9(){}
void Alarm10(){}
void Alarm11(){}

void BeginStep(){}
void Step(){}
void EndStep(){}

void Collision( int objType, int objId, Object @other){}

void Key( int key){}
void KeyPressed( int key){}
void KeyReleased( int key){}

void MouseButton( int button){}
void MouseButtonPressed( int button){}
void MouseButtonReleased( int button){}

void JoystickButton( int id, int button){}
void JoystickButtonPressed( int id, int button){}
void JoystickButtonReleased( int id, int button){}

void OutsideRoom(){}
void OutsideView(){}
void IntersectBoundary(){}

void GameStart(){}
void GameEnd(){}

void RoomStart(){}
void RoomEnd(){}

void NoMoreLives(){}
void NoMoreHealth(){}

void AnimationEnd(){}
void EndOfPath(){}
void Draw(){}

//======= Collision =========
bool place_meeting( float mX, float mY, int type)
{
return object.PlaceMeeting( mX, mY, type);
}

bool place_meeting_depth( float mX, float mY, int depth, int type)
{
    return object.PlaceMeetingDepth( mX, mY, type, depth);
}

Base_Object @object_place( float mX, float mY, int type)
{
    Base_Object @base = null;
    Object @obj = object.ObjectPlace( mX, mY, type);

    if (@obj != null)
        @base = cast<Base_Object>(@obj.GetScriptObject());

    return base;
}

bool collision_rectangle( float x1, float y1, float x2, float y2, int type)
{
    return object.CollisionRectangle( x1, y1, x2, y2, type);
} 

//========== Misc ===========
uint GetId()
{
return object.GetId();
}

void SetRect( int l, int t, int w, int h)
{
    object.general_rect.left = l;
    object.general_rect.top = t;
    object.general_rect.right = l+w;
    object.general_rect.bottom = t+h;
}

/*Base_Object@ opAssign(Base_Object_IMP @in)
{
    return @cast<Base_Object>( @in.GetScriptObject());
}*/

//======= Variables =========
Object @object;
float x;
float y;
int sprite_index;
int mask_index;
int image_index;
int depth;
} 

I'm thinking there's problem with classes because it doesn't fail when compiling just a simple function. The assert in the following code section fails because there is a null pointer to scriptData:

void asCScriptFunction::JITCompile()
{
asIJITCompiler *jit = engine->GetJITCompiler();
if( !jit )
return;

asASSERT( scriptData );

........

Even something as simple as this doesn't compile:

class test
{
void t(){}
}

Note that this will compile:

void t(){};

Now with further investigation I found that the function data for "t()" in the virtual function table of asIObjectType is valid (but where ever the module gets it from, it is not). Shouldn't angelscript be calling JITCompile() on the function in the virtual table? I'm still quite unfamiliar of how AS handles class methods, but whatever has changed since version 2.26.3 has broken the JIT.


Edited by justin12343, 16 September 2013 - 03:26 AM.


#6 Andreas Jonsson   Moderators   -  Reputation: 3264

Like
0Likes
Like

Posted 16 September 2013 - 08:09 AM

There is a bug in void asCScriptFunction::JITCompile() in version 2.27.1. This has already been fixed in the WIP version. The corrected version looks like this:

 

// internal
void asCScriptFunction::JITCompile()
{
    if( funcType != asFUNC_SCRIPT )
        return;

    asASSERT( scriptData );

    asIJITCompiler *jit = engine->GetJITCompiler();
    if( !jit )
        return;

    // Release the previous function, if any
    if( scriptData->jitFunction )
    {
        engine->jitCompiler->ReleaseJITFunction(scriptData->jitFunction);
        scriptData->jitFunction = 0;
    }

    // Compile for native system
    int r = jit->CompileFunction(this, &scriptData->jitFunction);
    if( r < 0 )
    {
        asASSERT( scriptData->jitFunction == 0 );
    }
}

 

Regards,

Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS