我在我的应用程序中遇到了一个非常奇怪的错误。这是一款使用 Bullet Physics 的视频游戏在其他图书馆中。
实现 SQLite 接口(interface)后,碰撞检测变得一团糟。玩家从地形中掉落,或与看不见的物体相撞。对我来说,这看起来像是错误的内存访问。不过,数据库功能运行良好。
我已经可以缩小问题的范围了。 SQLite 接口(interface)使用由不同可存储类型提供的类型特征。当注释掉所有特征特化时,碰撞工作正常。
如何找到这个错误的原因?如果有任何其他信息对解决问题有用,请告诉我,以便我可以将其包含在问题中。
更新:这是我需要为正确的碰撞添加注释的代码。可存储类型是Person
。
type/person/type.h
#pragma once
struct Person
{
float Height, Mass;
// ...
};
type/person/trait.h
#pragma once
#include "type.h"
#include "manager/data/manager.h"
using namespace std;
template <>
struct ManagerDataTrait<Person>
{
static const unordered_map<string, string> Fields;
static void Serialize(Person *Instance, ManagerData::Serialization *Data)
{
Data->FLOAT("height", Instance->Height);
Data->FLOAT("mass", Instance->Mass);
}
static void Deserialize(Person *Instance, ManagerData::Deserialization *Data)
{
Instance->Height = Data->FLOAT("height");
Instance->Mass = Data->FLOAT("mass");
}
};
type/person/general.cpp
#include "type.h"
#include "trait.h"
using namespace std;
const unordered_map<string, string> ManagerDataTrait<Person>::Fields = []{
unordered_map<string, string> fields;
fields.insert(std::make_pair("height", "FLOAT"));
fields.insert(std::make_pair("mass", "FLOAT"));
return fields;
}();
最佳答案
用户Yakk在评论中回答了我的问题。
The specialization should be visible adjacent to the type. Undefined behavior occurs if one unit sees it and another does not.
关于c++ - 如何调试由类型特征引起的这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20445840/