I have an function declaration of "void opCast(?&out)" on a class with asOBJ_REF, and I'm running into an interesting problem.
In 1 very specific case, (I can't seem to reproduce it in a clean test script), there seems to be either an AddRef too many or a Release too little.
I can fix it by making a small change to my script. The following causes there to be 5 AddRef's, and 5 Releases, which is the expected behavior:
auto a = g_scene.Mobils[0];
auto b = cast<CControlBase>(a);
if (b !is null) {
// ...
} else {
// ...
}
But the following produces 5 AddRef's and 4 Releases:
auto b = cast<CControlBase>(g_scene.Mobils[0]);
if (b !is null) {
// ...
} else {
// ...
}
I checked if the typeId happens to be different in the opCast function (thought maybe const could be at play or so) but it seems like that's the same in both situations. I do an AddRef myself in the opCast function when returning the casted handle.