崩溃后m = XMMatrixIdentity() - 在类中的配额内存? [英] Crash after m = XMMatrixIdentity() - aligment memory in classes?

查看:513
本文介绍了崩溃后m = XMMatrixIdentity() - 在类中的配额内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看DirectX SDK中的教程。教程5工作正常,但在我复制并分离代码到我自己的类,我在启动我的应用程序时出现奇怪的错误。

I was looking at the tutorials in DirectX SDK. Tutorial 5 works fine, but after I have copied and separated the code to my own classes, I got strange error during launching my application.

行是:

g_World1 = XMMatrixIdentity();

因为它,我在xnamathmatrix.int operator =中出现错误,看起来像:

Because of it, I got error in xnamathmatrix.int operator= which looks like that:

XMFINLINE _XMMATRIX& _XMMATRIX::operator=
(
    CONST _XMMATRIX& M
)
{
    r[0] = M.r[0];
    r[1] = M.r[1];
    r[2] = M.r[2];
    r[3] = M.r[3];
    return *this;
}

错误讯息是:

Access violation reading location 0xffffffff

读取某处可能由连接到XMFLOAT4X4 / XMMATRIX的东西造成:

I have read somewhere that it could be caused by something connected to XMFLOAT4X4 / XMMATRIX:


您是否考虑过使用XMFLOAT4X4存储矩阵, XMMATRIX?

Have you considered using XMFLOAT4X4 to store the matrix, and only using XMMATRIX?

但我认为我已经使用XMMATRIX了。

But I think I already use XMMATRIX.

MyClass。 h:

MyClass.h:

private:
    XMMATRIX g_World1;

MyClass.cpp:

MyClass.cpp:

void init(){
   g_World1 = XMMatrixIdentity();
}

我不认为我应该更改XMMATRIX g_World1;到XMFLOAT4X4 g_World1,因为它会产生如下错误:

I don't think I should change XMMATRIX g_World1; to XMFLOAT4X4 g_World1, because it produces errors like:


错误C2679:binary'=':无操作符找到一个右手操作数'XMMATRIX'类型(或者没有可接受的转换)

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'XMMATRIX' (or there is no acceptable conversion)

那么问题是什么? / p>

So, what's the problem?

推荐答案

XMVECTOR和XMMATRIX是注册代理类型。您可以安全地将它们用作Xbox 360,Xbox One和Windows x64平台的类型,因为它们对于堆栈上的数据和堆上分配的数据本身都有16字节对齐。

XMVECTOR and XMMATRIX are the 'register proxy' types. You can use them safely as types for the Xbox 360, Xbox One, and Windows x64 platforms as they all natively have 16-byte alignment for the data on the stack and allocated on the heap.

使用它们在Windows 32位或Windows RT / ARM需要更多的努力,因为本机对齐不到16字节。一种方法是DirectX Tool Kit使用的技术...它使用pImpl idiom和pImpl内部类明确地分配16字节对齐,这是直接使用XMVECTOR和XMMATRIX类型。另一种方法是使用所有各种存储类型,如XMFLOAT4和XMFLOAT4X4。

Using them for Windows 32-bit or Windows RT/ARM takes more effort since the native alignment is les than 16-bytes. One approach is the technique used by DirectX Tool Kit... it uses the pImpl idiom and the pImpl internal classes are explicitly allocated with 16-byte alignment which is where XMVECTOR and XMMATRIX types are used directly. Another approach is to use all the various 'storage' types like XMFLOAT4 and XMFLOAT4X4.

注意: DirectXMath程序员指南涵盖了这一点。

Note: the DirectXMath programmer's guide covers this. It's not a long document to read, and it's packed with a lot of hints and recommendations.

PS:有一个版本的标准Direct3D教程为Win32桌面上的MSDN代码不需要DirectX SDK的图库...它只使用VS 2012或VS 2013附带的Windows 8.x SDK。在此输入链接描述

PS: There's a version of the standard Direct3D tutorials for Win32 desktop on MSDN Code Gallery that does not require the DirectX SDK... it just uses the Windows 8.x SDK included with VS 2012 or VS 2013.enter link description here

这篇关于崩溃后m = XMMatrixIdentity() - 在类中的配额内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆