Archive 19/01/2023.

Null pointer excepotion in script

rogerdv

I started playing with AngelScript yesterday and of course, found my first problem:

[Tue Nov 25 07:49:46 2014] ERROR: Scripts/keyw.as:11,2 - Exception 'Null pointer access' in 'void Start()' AngelScript callstack: Scripts/keyw.as:void Start():11,2

This is the main code:

[code] #include “Scripts/Engine/IsoCamera.as”

Scene@ gameScene;
IsoCamera@ cam;

void Start()
{
gameScene = Scene(“castle-gates”);
gameScene.LoadXML(cache.GetFile(“Scenes/NinjaSnowWar.xml”));
cam = IsoCamera(); <----- This is the error line

if (!engine.headless)
{
    renderer.viewports[0] = Viewport(gameScene, cam.gameCamera);
}

}
[/code]

This is the camera creation code:

[code]class IsoCamera
{
IsoCamera()
{
target = Node();
camNode = target.CreateChild(“camnod”);
gameCamera = camNode.CreateComponent(“Camera”);
camNode.position = Vector3(0, 55, 52);
camNode.LookAt(target.position);
}

void SetPosition(Vector3 pos)
{
	target.position = pos;
}
Node@ target;
Node@ camNode;
Camera@ gameCamera;

}[/code]

Can somebody seee where is my mistake?

Azalrion

Since IsoCamera is a class defined in the script and so can be value assigned as well you need to put:

   @cam = IsoCamera();

Instead.

rogerdv

Hmm, I tried removing @ from IsoCamera@ cam; and worked too. Is that correct too?

Azalrion

Yes. An @ symbol is a handle see: angelcode.com/angelscript/sd … andle.html .

Its only not needed for urho defined c++ (or custom defined c++ classes) that don’t support value assignment (using certain asBEH_ when defining the class in c++), any classes you declare in scripts and have a variable declaration using the handle will need to be assigned @varname = Var();. If you’re not passing the variable around lots no need to use a handle, if you are you’d probably prefer it, its a wierd mix of c++ reference and pointer.