Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用lambdas的std::函数分配上的访问冲突_C++_Visual C++_C++11_Access Violation_Physx - Fatal编程技术网

C++ 使用lambdas的std::函数分配上的访问冲突

C++ 使用lambdas的std::函数分配上的访问冲突,c++,visual-c++,c++11,access-violation,physx,C++,Visual C++,C++11,Access Violation,Physx,大家好,又来了。继续上一个问题中的代码: 我纠正了这一点,使用了建议的克隆方法,但在我尝试memcpy之前也发生了一个错误(请阅读上面的问题) 我试图做的是创建一个lambda来捕获当前脚本并执行它,然后将该lambda传递并存储在成员InternalCallback中的一个对象(触发器*)中。 我在lambda分配中遇到访问冲突错误: 该错误仅在该代码的第4次迭代时发生: if(CheckHR(EnginePTR->iPhysics->CreateFromFile(physicsP

大家好,又来了。继续上一个问题中的代码: 我纠正了这一点,使用了建议的克隆方法,但在我尝试memcpy之前也发生了一个错误(请阅读上面的问题)

我试图做的是创建一个lambda来捕获当前脚本并执行它,然后将该lambda传递并存储在成员InternalCallback中的一个对象(触发器*)中。
我在lambda分配中遇到访问冲突错误: 该错误仅在该代码的第4次迭代时发生:

if(CheckHR(EnginePTR->iPhysics->CreateFromFile(physicsPath,StartingTriggerID,trans,scale,-1,false,engPtr)) == HR_Correct)
{
     _Lua::ScriptedEntity * newScript = EntityBase->Clone(vm);//nullptr;

     string luaPath = transforms.next_sibling().next_sibling().first_attribute().as_string();
     if(UseRelativePaths)
     { 
         stringstream temp2;
         temp2 << _Core::ExePath() << LuaSubfolder << "\\" << luaPath;
         luaPath = temp2.str();
     }

     newScript->CompileFile(luaPath.c_str());
     newScript->EnginePTR_voidptr = engPtr;

     auto callback = [=](_Physics::Trigger* trigger,PxTriggerPair* pairs, PxU32 count) 
                        {
                            newScript->SelectScriptFunction("TriggerCallback");
                            newScript->AddParam(trigger->Id);

                            auto data = (_Physics::RayCastingStats*)pairs->otherShape->userData;

                            newScript->AddParam((PxU8)pairs->flags);
                            newScript->AddParam(data->ID);
                            newScript->AddParam((int)data->Type);

                            newScript->AddParam((int)count);

                            newScript->Go(1);

                            return;
                        };

     ((_Physics::Trigger*)EnginePTR->iPhysics->GetPhysicObject(StartingTriggerID))->InternalCallback = callback;

     StartingTriggerID++;
}
if(CheckHR(EnginePTR->iPhysics->CreateFromFile(physicpath,StartingTriggerID,trans,scale,-1,false,engPtr))==HR\u Correct)
{
_Lua::ScriptedEntity*newScript=EntityBase->Clone(vm);//nullptr;
string luaPath=transforms.next_sibling().next_sibling().first_attribute().as_string();
if(userelativepath)
{ 
stringstreamtemp2;
temp2 AddParam(触发器->Id);
自动数据=(_Physics::RayCastingStats*)对->其他形状->用户数据;
newScript->AddParam((PxU8)对->标志);
newScript->AddParam(数据->ID);
newScript->AddParam((int)数据->类型);
newScript->AddParam((int)计数);
newScript->Go(1);
返回;
};
((_physical::Trigger*)EnginePTR->iPhysics->GetPhysical对象(StartingTriggerID))->InternalCallback=callback;
StartingTriggerID++;
}
这是触发器的代码

class Trigger : public PhysicObject
    {
    public:
        Trigger()
        {
            ActorDynamic = nullptr;
            ActorStatic = nullptr;
            InternalCallback = nullptr;
        }
        virtual HRESULT Update(float ElapsedTime,void * EnginePTR);
        virtual HRESULT Cleanup(); // Release the actor!!

        long Id;
        ShapeTypes Type;
        static const PhysicObjectType PhysicsType = PhysicObjectType::Trigger;
        PxVec3 Scale;

        void* UserData;
        void Callback(PxTriggerPair* pairs,PxU32 count)
        {
            InternalCallback(this,pairs,count);
        }

        function<void(_Physics::Trigger* trigger,PxTriggerPair* pairs, PxU32 count)> InternalCallback;
    };
类触发器:公共物理对象
{
公众:
触发器()
{
ActorDynamic=nullptr;
ActorStatic=nullptr;
InternalCallback=nullptr;
}
虚拟HRESULT更新(float ElapsedTime,void*EnginePTR);
虚拟HRESULT Cleanup();//释放参与者!!
长Id;
形态类型;
静态常量PhysicObjectType PhysicType=PhysicObjectType::Trigger;
PxVec3标度;
void*用户数据;
无效回调(PxTriggerPair*对,PxU32计数)
{
InternalCallback(这个、对、计数);
}
函数内部回调;
};
我所说的迭代是指这是for循环的一部分。 我的系统是Win 7 64位、Intel i3、NVIDIA GTX 480和编译器Visual Studio 2012 Express,使用C++11工具集。 我真的没有主意了。我测试了堆损坏,它看起来不错,我在lambda中更改了捕获,没有更改任何内容,我跳过了第4个对象,它工作了。 任何帮助都将不胜感激


编辑:根据需要,这里是调用堆栈:

已解决。这是一个设计错误。我在一个映射中存储了很多对象,它们都派生自一个对象类(如上所述,触发器派生自Physical object)。 问题是我遇到了IDs冲突,所以ID5中存储的对象不是触发器,所以cast创建了一个坏对象,所以程序崩溃了


愚蠢的错误,非常具体,但它可能会帮助人们记住检查时态对象。

Uhm-错误没有提供大量信息,人们需要详细查看调用堆栈。调用堆栈在左侧,但我将上载一个新的,只有调用堆栈