Archive 17/01/2023.

Assertion failure when trying to access node from function

sherb3t

The node is as a public SharedPtr

Here is the function:

int getPlayerPos(int comp) {
	Vector3 playerPos = playerNode_->GetWorldPosition();

	if (comp) {
		return round(playerPos.z_ / 6);
	}
	else {
		return round(playerPos.x_ / 6);
	}
}

The function is called within HandleUpdate(). If you need more code just ask.

rku

playerNode_ is probably empty (null). Make it not null.

Modanung

Or check whether the playerNode_ is null. If it is, avoid accessing its members and methods.

Also, welcome to the forums! :confetti_ball: :slightly_smiling_face:

sherb3t

I do not believe that the node is null. Running this code within the Start() function causes no problems:

Vector3 playerPos = playerNode_->GetWorldPosition();

rku

Do not believe. Debug.

Modanung

@sherb3t Try adding assert(playerNode_); before you otherwise use the pointer and see if the assertion fails.

sherb3t

Still fails. Thanks for the help.

Modanung

If the pointer is null the assertion should indeed fail.

sherb3t

How do I check if it’s null. I’m pretty sure it isn’t because I’m using it no problem in the start function…

sherb3t

The pointer is infact null when accessed from the function. When I try and check in the Start() function I get an error with this code:

if (playerNode_.Null()) {
std::cout << “yes its null \n”;
}

The error is “expression must have a class type”.