Obliviere
15-09-2006 00:00:55
Sorry if this is an elementary question, but I've been tinkering and researching this, and I'm out of ideas. I'm trying to implement mouse picking in my program, and this function call works perfectly in debug mode. However, when performing it in release mode, it works for the first time, and then any subsequent function calls cause it to crash.
bool doPicking( Ogre::Real relX, Ogre::Real relY, Ogre::Vector3& globalPosition, Ogre::Real length )
{
if( mCurrentObject )
mCurrentObject->showBoundingBox( false );
mCurrentObject = 0;
Ogre::Ray *ray = &mExCamera->getCamera()->getCameraToViewportRay(relX, relY);
OgreOde::RayCollision *rayCol = new OgreOde::RayCollision( 0.0, Space, ray->getOrigin(), ray->getDirection()); (! fails here!)
OgreOde::Geometry *colGeom = rayCol->castRay(globalPosition);
rayCol = 0;
delete rayCol;
.
.
.
}
When it fails on the second iteration, it gives the new rayCol line as the error, but it seems to be properly deleting it? Any thoughts would be appreciated, thanks!
tuan kuranes
15-09-2006 09:39:59
If it happens only on release mode, that may come from any other portion of code in application causing a memory corruption making this call going bad. (Check Ogre Faq about surviving Debug to Release code upgrade.)
AnyWay:
Did you check how zombie picking is done in SimplesScenes Demos ?
It's a much Better way to do things :
1. is use Ogre ray scene query to narrow search on object picked upon their bounding box, using scene manager particular geometry to speed up a lot picking.
2. it uses a RayGeometry and collide it against other geoms. You can go even further and allocate you rayGeometry once and for all, so that picking doesn't need a new/delete call. (which is costly.)
that way you can allocate it once and for all, just changing its definition when needed.
Here's an idea (wihtout Ogre Pre picking.)
bool doPicking( Ogre::Real relX, Ogre::Real relY, Ogre::Vector3& globalPosition, Ogre::Real length )
{
if( mCurrentObject )
mCurrentObject->showBoundingBox( false );
mCurrentObject = 0;
Ogre::Ray *ray = &mExCamera->getCamera()->getCameraToViewportRay(relX, relY);
myRayGeom->setDefinition(ray.getOrigin(),ray.getDirection());
if (rayGeom->collide(mCurrentObject->getOgreOdeGeometry, mylistener) != 0)
{
//does Collide.
}
}
Obliviere
20-09-2006 17:41:21
Yeah I already looked at that page... it seems to be almost a standard amongst developers, as every link I found went to it.
Been hacking at this for awhile; I'm just learning ODE as well as trying to sort through what a teammate has done, so I might be doing things backwards. But the sample pseudocode you've given, that's what might be used if you're expecting it to collide with a specific object, right?
If I were instead to try and find out what it might hit *first* in a scene, I'd have to traverse the scene graph? Is that kind of what you were trying to accomplish with the ragdoll iterator?
tuan kuranes
20-09-2006 17:45:22
Ogre scenequery support "sorting" results, it's commented in simplescene demo as firing shoot multiples zombies at a time.
You should really study the sample to see how to do that simply and fast.
Ragdoll iterator is just a way to find which ragdoll the query did returned. that could be done in a smarter way, adding a casting movable results pointer into ragdoll object.
galeonis
29-09-2006 19:46:02
Sorry if this is an elementary question, but I've been tinkering and researching this, and I'm out of ideas. I'm trying to implement mouse picking in my program, and this function call works perfectly in debug mode. However, when performing it in release mode, it works for the first time, and then any subsequent function calls cause it to crash.
You can't know how happy I was to read that someone else is having the same... well a similar problem. I've been banging my head on an issue that's somewhat like this picking issue, and my wife has been giving me some very dirty looks about the language I've been using.
Tuan (Obliviere or anyone else!!!), I've already checked Ogre Faq about surviving Debug to Release, and I've been looking at Tuan's sample here for a little while. However, I still can't get this to work.
Could someone possibly expand on this answer? I'm still pretty new at all of this so any help would be appreciated.
Regards
tuan kuranes
02-10-2006 12:50:06
The only way to help you more would be looking at your entire code and review it to find problems in it.