c++ - 如何调试由类型特征引起的这个错误?

标签 c++ sqlite memory typetraits bulletphysics

我在我的应用程序中遇到了一个非常奇怪的错误。这是一款使用 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/

相关文章:

android - 如何在 Honeycomb 中获取外部内存分配?

安卓:SQLiteDatabase InsertWithOnConflict API 7

c - 如何在 CPP 的 SQLite 中截断表?

c - 分配连续物理内存的方法

c++ - 使用共享逻辑 (MVC) 将 Qt 桌面应用程序扩展到 Web 服务

java - 如何从android中的游标检索数据?

c - 使用 realloc 和 strdup 分配时 Valgrind 检测到错误

c++ - 如果我不给它一点额外的空间,弦就会发疯。谁能解释这里发生了什么?

c++ - 在线程之间传输函数调用

c++ - 用于枚举的正确转换是什么?