port of "enhanced weapons" needs debugging. help?
by deepscratch · in Torque 3D Professional · 09/21/2009 (5:16 pm) · 9 replies
hi all,
I got permission from Ron Nelson to port his enhanced weapons resource to T3D, it builds without errors, and works fine, except when you shoot any shapeBase object, it throws this:
(Vector<T>::operator[] - out of bounds array access!)
in this line "template<class T> inline T& Vector<T>::operator[](U32 index)"
I honestly am out of my depth trying to find out why.
can a coding guru please take a look and see why?
then it can be added to resources.
if you use your original projectile.cpp and projectile.h, there are no crashes, and everything else works fine (killing particles and whatnot)
the link
has the full port, all the scripts ported, and materials.cs files. any models from the resource I did not add, to save space, so get them from the 1.8.1
the build install instructions are the same as for the 1.8.1 resource, and this was built on the full template.
thanks in advance for any help you can give with this.
cheers
I got permission from Ron Nelson to port his enhanced weapons resource to T3D, it builds without errors, and works fine, except when you shoot any shapeBase object, it throws this:
(Vector<T>::operator[] - out of bounds array access!)
in this line "template<class T> inline T& Vector<T>::operator[](U32 index)"
I honestly am out of my depth trying to find out why.
can a coding guru please take a look and see why?
then it can be added to resources.
if you use your original projectile.cpp and projectile.h, there are no crashes, and everything else works fine (killing particles and whatnot)
the link
has the full port, all the scripts ported, and materials.cs files. any models from the resource I did not add, to save space, so get them from the 1.8.1
the build install instructions are the same as for the 1.8.1 resource, and this was built on the full template.
thanks in advance for any help you can give with this.
cheers
About the author
email me at medan121@gmail.com
Recent Threads
#2
it seems to happen with ANY shapeBase object that you shoot.
09/21/2009 (5:59 pm)
can you explain more Picasso?it seems to happen with ANY shapeBase object that you shoot.
#3
09/21/2009 (6:27 pm)
Can you catch this before the assert and look at the call stack to see where the call is coming from?
#4
its the rayCastTri and point3F.
the blue line is where the trouble begins, in the projectiles proccessTick

this
is the uncut image
a bit more info:
it gives this three times,
Fatal - Vector<T>: operator[] - out of bounds array access!
then points here:
inline Point3F Point3F: operator-(const Point3F& _rSub) const
{
return Point3F(x - _rSub.x, y - _rSub.y, z - _rSub.z);//CRASH HERE
}
I believe the three times are for each of the three points.
09/21/2009 (6:57 pm)
yes, here is a screen of the stack,its the rayCastTri and point3F.
the blue line is where the trouble begins, in the projectiles proccessTick

this
is the uncut image
a bit more info:
it gives this three times,
Fatal - Vector<T>: operator[] - out of bounds array access!
then points here:
inline Point3F Point3F: operator-(const Point3F& _rSub) const
{
return Point3F(x - _rSub.x, y - _rSub.y, z - _rSub.z);//CRASH HERE
}
I believe the three times are for each of the three points.
#5
10/05/2009 (4:52 pm)
no one?
#7
To fix this, replace the function called castRayTri, with the one below:
01/04/2012 (6:50 pm)
The error comes from: ./Engine/source/ts/tsMesh.cppTo fix this, replace the function called castRayTri, with the one below:
//Ron Nelson/Deepscratch: Enhanced Projectiles for T3D --- Start ---
bool TSMesh::castRayTri( S32 frame, const Point3F& start, const Point3F& end, TriRayInfo* rayInfo, TSMaterialList* materials )
{
// Loop thru the triangles of the first frame.
const S32 firstVert = vertsPerFrame * frame;
F32 hit = F32_MAX;
Point3F dir( end - start );
dir.normalizeSafe();
for ( S32 i = 0; i < primitives.size(); i++ )
{
const TSDrawPrimitive& draw = primitives[i];
AssertFatal( draw.matIndex & TSDrawPrimitive::Indexed, "TSMesh::castRayTri, got non-indexed primitive!" );
// gonna depend on what kind of primitive it is...
if ( ( draw.matIndex & TSDrawPrimitive::TypeMask ) == TSDrawPrimitive::Triangles )
{
for ( S32 j=0; j < draw.numElements; j+=3 )
{
const U32 idx0 = indices[draw.start+j+0] + firstVert;
const U32 idx1 = indices[draw.start+j+1] + firstVert;
const U32 idx2 = indices[draw.start+j+2] + firstVert;
F32 h, u, v;
if ( MathUtils::rayTriangleIntersect( start, dir, mVertexData[firstVert + idx2].vert(), mVertexData[firstVert + idx1].vert(),
mVertexData[firstVert + idx0].vert(), &h, &v, &u ) && h < hit )
{
hit = h;
rayInfo->distance = hit;
rayInfo->point = start + ( dir * hit );
U32 matIndex = draw.matIndex & TSDrawPrimitive::MaterialMask;
if (materials && materials->getMaterialCount() > 0)
rayInfo->material = materials->getMaterialInst( matIndex );
else
rayInfo->material = NULL;
Point3F temp[3] =
{
mVertexData[firstVert + idx0].vert(),
mVertexData[firstVert + idx1].vert(),
mVertexData[firstVert + idx2].vert()
};
Point3F bc = MathUtils::getBarrycentricCoord( rayInfo->point, temp );
rayInfo->uv = Point2F(
(bc.x * mVertexData[firstVert + idx0].tvert().x) + (bc.y * mVertexData[firstVert + idx1].tvert().x) + (bc.z * mVertexData[firstVert + idx2].tvert().x ),
(bc.x * mVertexData[firstVert + idx0].tvert().y) + (bc.y * mVertexData[firstVert + idx1].tvert().y) + (bc.z * mVertexData[firstVert + idx2].tvert().y ) );
}
}
}
else
{
AssertFatal( ( draw.matIndex & TSDrawPrimitive::Strip ) == TSDrawPrimitive::Strip, "TSMesh::castRayTri, unexpected primitive type!" );
U32 idx0 = indices[draw.start + 0] + firstVert;
U32 idx1;
U32 idx2 = indices[draw.start + 1] + firstVert;
U32* nextIdx = &idx1;
for ( S32 j = 2; j < draw.numElements; j++ )
{
*nextIdx = idx2;
nextIdx = (U32*) ( (dsize_t)nextIdx ^ (dsize_t)&idx0 ^ (dsize_t)&idx1);
idx2 = indices[draw.start + j] + firstVert;
F32 h, u, v;
//Added by Sorin D.
if(MathUtils::rayTriangleIntersect( start, dir, mVertexData[firstVert + idx2].vert(),
mVertexData[firstVert + idx1].vert(),
mVertexData[firstVert + idx0].vert(), &h, &v, &u ) && h < hit )
//Added by Sorin D. End
{
hit = h;
rayInfo->distance = hit;
rayInfo->point = start + ( dir * hit );
U32 matIndex = draw.matIndex & TSDrawPrimitive::MaterialMask;
if (materials && materials->getMaterialCount() > 0)
rayInfo->material = materials->getMaterialInst( matIndex );
else
{
rayInfo->material = NULL;
}
Point3F temp[3] =
{
mVertexData[firstVert + idx0].vert(),
mVertexData[firstVert + idx1].vert(),
mVertexData[firstVert + idx2].vert()
};
Point3F bc = MathUtils::getBarrycentricCoord( rayInfo->point, temp );
rayInfo->uv = Point2F(
(bc.x * mVertexData[firstVert + idx0].tvert().x) + (bc.y * mVertexData[firstVert + idx1].tvert().x) + (bc.z * mVertexData[firstVert + idx2].tvert().x ),
(bc.x * mVertexData[firstVert + idx0].tvert().y) + (bc.y * mVertexData[firstVert + idx1].tvert().y) + (bc.z * mVertexData[firstVert + idx2].tvert().y ) );
}
}
}
}
return hit < F32_MAX;
}
//Enhanced Projectiles
//Ron Nelson/Deepscratch: Enhanced Projectiles for T3D --- End ---
#8
05/13/2014 (9:38 pm)
I know it has been a while since I tinkered with this code. I just wanted to say thanks to deepscratch for the conversion and another thanks to Sorin. His replacement function works perfectly.
#9
05/14/2014 (4:37 am)
Oi, yeah thanks for the update on this. I'll patch this and throw it onto the http://abighole.hngamers.com
Torque Owner Ivan Mandzhukov
Liman3D
You can easily get it with wrong artist's work.