Hi,
I am migrating to AS 2.31 (more precisely revision 2301), and I am seeing a change in behavior regarding null pointer exceptions.
I have a class that implements an array-style opIndex. The C++ implementation is the following:
void * CollectionClass::opIndex(asUINT index)
{
if(index<size)
return items[index];
else
return NULL;
}
When accessing a collection of collection out of bounds in a script:
// out of bound: myCollection contains only 1 item
myCollection[2][2];
This used to raise a null pointer exception in the script engine (AS 2.29.2), whereas now it crashes: after checking the code in Angelscript, the null pointer check has indeed been removed, and the returned pointer is dereferenced directly to call the opIndex operator on it (as_scriptengine.cpp, line 4286):
obj = (void*)(asPWORD(obj) + i->baseOffset);
return (((asCSimpleDummy*)obj)->*f)(param1);
Is this expected? Should I raise an out of bounds exception manually instead to stop execution before, like it is done in the array class?
I am thinking that there are probably many cases where you'd like the engine to check for null pointers for you instead, like it used to do if I remember well, but I might be wrong!