Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Overloaded operator results in null pointer exception when result isn't stored in variable

$
0
0
Best to describe with some code. This works: vec3 diff = s.getPosition() - capturePosition; float length = length2(diff); And this throws null pointer exception (Null pointer access): float length = length2(s.getPosition() - capturePosition); "vec3" is registered type with overloaded operator "-". Is there any reason why it shouldn't work without storing result in variable? vec3 is registered as (leaving out unrelated stuff) engine->RegisterObjectType("vec3", sizeof(Vec3Primitive), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CDAK); engine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(vec3Constructor), asCALL_CDECL_OBJLAST); engine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f(float,float,float)", asFUNCTION(vec3Constructor3), asCALL_CDECL_OBJLAST); engine->RegisterObjectBehaviour("vec3", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(vec3Destructor), asCALL_CDECL_OBJLAST); engine->RegisterObjectMethod("vec3", "vec3 opSub(const vec3)", asMETHOD(Vec3Primitive,opSub), asCALL_THISCALL); engine->RegisterGlobalFunction("float length(const vec3)", asFUNCTION(Vec3Primitive::length), asCALL_CDECL); void vec3Constructor(void *memory){ new(memory) Vec3Primitive(); } void vec3Constructor3(float x, float y, float z, void *memory){ new(memory) Vec3Primitive(x, y, z); } void vec3Destructor(void *memory){ ((Vec3Primitive*)memory)->~Vec3Primitive(); } static float length2(const Vec3Primitive vec3){ return vec3.x * vec3.x + vec3.y * vec3.y + vec3.z * vec3.z; } Vec3Primitive opSub(const Vec3Primitive other){ return Vec3Primitive(x - other.x, y - other.y, z - other.z); } I'm using AngelScript version 2.31.1 I've registered this class some time ago and just now added operator overloading, which brought this error. Maybe I am doing something obviously wrong?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>