标签: visual-c++-2012

调试Win32应用程序挂起

我无法在Win32应用程序中找到挂起的原因.该软件以紧凑的循环将一些数据呈现给OpenGL视觉:

std::vector<uint8_t> indices;
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_DOUBLE, 0, vertexDataBuffer);
while (...) {
    // get index type (1, 2, 4) and index count
    indices.resize(indexType * count);

    // get indices into "indices" buffer
    getIndices(indices.data(), indices.size()); //< seems to hang here!

    // draw (I'm using the correct parameters)
    glDrawElements(GL_TRIANGLES_*, count, GL_UNSIGNED_*);
}
glDisableClientState(GL_VERTEX_ARRAY);
Run Code Online (Sandbox Code Playgroud)

代码使用VC11 Update 1(CTP 3)编译.在运行优化的二进制文件时,它会getIndices()在几个循环之后挂起调用(更多关于此内容).我已经有了...

  • 三重验证了所有缓冲区,甚至是附加的CRC,以确保我没有任何缓冲区溢出
  • 在循环内添加了对HeapValidate()的调用,以确保堆没有损坏
  • 使用了ApplicationVerifier
  • 使用GFlags和PageHeap启用堆分配监控.
  • 当应用程序锁定时,它会进入WinDbg

我并没有找到该代码访问分配的缓冲区,也没有任何堆损坏任何问题.但是,如果我禁用低碎片堆,问题就会消失.如果我为indices缓冲区使用单独的(低碎片)堆,它也会消失.

无论如何,这是导致死锁的堆栈跟踪:

0:000> kb
ChildEBP RetAddr  Args to …
Run Code Online (Sandbox Code Playgroud)

c++ debugging exception-handling windbg visual-c++-2012

7
推荐指数
1
解决办法
2998
查看次数

如何使Visual Studio 2012调用本机64位Visual C++编译器而不是32位x64交叉编译器?

Visual Studio 2012似乎总是调用位于的32位版本而不是cl.exe位于%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\bin\x86_amd64的64 位版本%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\bin\amd64.

我尝试在属性表$(VCInstallDir)bin\amd64VC++目录部分的"可执行目录"列表的开头预先添加Microsoft.Cpp.x64.user,但这根本不起作用 - 当我重建时,我收到此错误:

TRACKER : error TRK0002: Failed to execute command: "
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64\CL.exe"
@C:\Users\<my_profile>\AppData\Local\Temp\tmpf3d817cafe064ad28e7dd62b2cb591c3.rsp
". The operation identifier is not valid.
Run Code Online (Sandbox Code Playgroud)

如何使Visual Studio 2012使用本机64位C++编译器?

c++ visual-c++ visual-studio-2012 visual-c++-2012

7
推荐指数
1
解决办法
7840
查看次数

我应该在我的类中的std :: vector成员变量中使用std :: unique_ptr <T>吗?

想象一下class C,有一个m_MyList类型的成员变量std::vector,我想在其中存储类型的对象MyClass.C有两个函数可以添加或删除对象m_MyList. m_MyList也应该让消费者可以访问,C因为他们需要阅读MyClass对象集合.集合的外部阅读器无法更改集合,因此MyClass对象仅由C.

现在我的问题是:在C++ 11风格中,向量中存储的最佳T是什么?可能性似乎是:

  • std::vector<MyClass>
  • std::vector<MyClass*>
  • std::vector<unique_ptr<MyClass>>使用std:moveunique_ptrvector

c++ stl smart-pointers c++11 visual-c++-2012

6
推荐指数
2
解决办法
2781
查看次数

std :: function绑定到成员函数

以下代码无法在VS2012中编译

class Zot
{
public:
    int A() { return 123; }
};

int _tmain(int argc, _TCHAR* argv[])
{
    std::function<int (Zot*)> fn = &Zot::A;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,将分配更改为

    std::function<int (Zot*)> fn = std::bind(&Zot::A, std::placeholders::_1);
Run Code Online (Sandbox Code Playgroud)

有用吗

有很多在线示例显示原始语法.在C++ 11规范中有什么变化来禁止这种语法吗?

是否有有效的简短表格?

编辑:编译器错误(为可重复性稍加编辑)是:

1>vc\include\functional(515): error C2664: 'std::_Func_class<_Ret,_V0_t>::_Set' : cannot convert parameter 1 from '_Myimpl *' to 'std::_Func_base<_Rx,_V0_t> *'
1>          with
1>          [
1>              _Ret=int,
1>              _V0_t=Zot *
1>          ]
1>          and
1>          [
1>              _Rx=int,
1>              _V0_t=Zot *
1>          ]
1>          Types pointed to …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ c++11 visual-c++-2012

6
推荐指数
2
解决办法
2199
查看次数

缺少Visual Studio 2012中Visual C++的先决条件

我最近安装了vs2012,我已经更新了我的ClickOnce应用程序.更确切地说,我第一次打开我的C++ project(依赖于我的主要c#项目)我没有更新它,一切正常.VS 2012仍然能够看到Visual C++ 2010的先决条件.后来我通过将Platform Toolset更改为"Visual Studio 2012 (v110)"under 来更新了我的项目Properties->Configuration Properties->General.

与此同时,我已经安装了其他版本software,现在我发现我无法为我的ClickOnce发布项目添加Visual C++先决条件.该Visual C++ 2010 Runtime Libraries (x64)前提标有黄色三角形,它是缺失的.理想情况下我想更新Visual C++ 2012 Runtime Libraries x64 (and x86),但即使这个先决条件也缺失了.

我想这是因为在文件夹C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper\Packages中相应的包(vcredist_x64)是空的.我也注意到,在控制面板中安装的程序列表中我已经Microsoft Visual C++ 2010 x64x86安装,同时可再发行版本和运行时版本(我认为他们在那里与Visual Studio 2010以前安装的),而我错过了在Visual C++ 2012文件.因此,我认为Visual C++ 2012没有与Visual Studio 2012结合在一起,不是吗?我甚至尝试通过下载来安装Visual C++ 2012 Redistributable x64软件包,现在它们已经在我安装的程序中列出,只有Redistributable,而不是Runtime版本.

但是先决条件仍然缺失.我怎么解决这个问题?我甚至想过手动复制引导程序包为Visual C++ 2010位于... \v7.0A\Bootstrapper\Packages文件夹,并手动更改它的C++ 2012,但我不知道我应该写在product.xml下面<MsiProductCheck …

clickonce prerequisites visual-studio-2012 visual-c++-2012

6
推荐指数
1
解决办法
6201
查看次数

绕过 C++ 中运算符 new 的重写

有没有办法实现绕过覆盖operator new

像这样的东西:

void* ::operator new( std::size_t size ) {
    void *p = ( ::operator new( size ) );  // But original, _not_ infinite recursion
    // do stuff with p
    return p; 
}
Run Code Online (Sandbox Code Playgroud)

背景: 我有一些遗留代码,我们最近改用 Visual Studio 2012 进行编译。现在,当内存块malloc不足时,我们会随机崩溃。_heap_alloc(是的,代码中到处都是小内存泄漏和其他不良行为。但不幸的是,彻底清理是不现实的,大约有 500 000 SLOC。)

我目前的理论是,原因是几乎所有源文件都包含具有以下覆盖的标头operator new

void* ::operator new( std::size_t size ) {
    void* p = malloc( size );
    if( p == NULL )
        throw;
    // set memory to zero
    memset( p, 0, size …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading new-operator visual-c++-2012

6
推荐指数
1
解决办法
1808
查看次数

合并Visual C++ 2012项目过滤器时如何防止系统冲突?

将新文件添加到Visual C++项目时,IDE会将它们添加到两个位置:

  • 主项目文件(例如myproject.vcxproj)
  • 项目"过滤器",解决方案资源管理器的虚拟路径的存储库(例如myproject.vcxproj.filters)

合并文件添加对主项目文件来说不是问题,但它通常是过滤器冲突的根源.问题来自于IDE总是在过滤器列表的最末端添加新元素.

为了说明这个问题,我们假设过滤器最初看起来像这样:

1 <ClInclude Include="fs\path\oldFile1.h">
2   <Filter>virtual\path</Filter>
3 </ClInclude>
4 <ClInclude Include="fs\path\oldFile2.h">
5   <Filter>virtual\path</Filter>
6 </ClInclude>
Run Code Online (Sandbox Code Playgroud)

然后程序员A添加newFileA.h并提交,过滤器更新如下:

1 <ClInclude Include="fs\path\oldFile1.h">
2   <Filter>virtual\path</Filter>
3 </ClInclude>
4 <ClInclude Include="fs\path\oldFile2.h">
5   <Filter>virtual\path</Filter>
6 </ClInclude>
7 <ClInclude Include="fs\path\newFileA.h">
8   <Filter>virtual\path</Filter>
9 </ClInclude>
Run Code Online (Sandbox Code Playgroud)

如果程序员B还添加了一个newFileB.h并且在头版本上同步的注释,那么他的本地过滤器副本将如下所示:

1 <ClInclude Include="fs\path\oldFile1.h">
2   <Filter>virtual\path</Filter>
3 </ClInclude>
4 <ClInclude Include="fs\path\oldFile2.h">
5   <Filter>virtual\path</Filter>
6 </ClInclude>
7 <ClInclude Include="fs\path\newFileB.h">
8   <Filter>virtual\path</Filter>
9 </ClInclude>
Run Code Online (Sandbox Code Playgroud)

试图与程序员A的变化同步将系统地引起程序员B的第7-8-9行的合并冲突.这是因为变化恰好发生在完全相同的位置.

有没有办法防止这个问题发生,无论是通过Visual Studio中的配置更改,某些合并工具(最好是 Araxis Merge或Beyond Compare)的特殊选项,还是其他任何东西?

merge merge-conflict-resolution visual-studio-2012 visual-c++-2012

6
推荐指数
1
解决办法
1462
查看次数

通过解除引用复制std :: unique_ptr的值

我编写了以下代码,我尝试将unique_ptr对象的值复制到结构中.

#include <iostream>
#include <memory>
using namespace std;

struct S {
    S(int X = 0, int Y = 0):x(X), y(Y){}

    // S(const S&) {}
    // S& operator=(const S&) { return *this; }

    int x;
    int y;
    std::unique_ptr<S> ptr;
};

int main() {
    S s;
    s.ptr = std::unique_ptr<S>(new S(1, 4));
    S p = *s.ptr; // Copy the pointer's value
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它在Visual C++ 2012中弹出错误:

IntelliSense:没有合适的用户定义从"S"到"S"的转换
IntelliSense:没有运算符"="匹配这些操作数操作数类型是:std :: unique_ptr> = std :: unique_ptr>
错误C2248:'std :: unique_ptr <_Ty> :: unique_ptr':无法访问类'std …

c++ unique-ptr c++11 visual-c++-2012

6
推荐指数
1
解决办法
6993
查看次数

使用最终说明符专门化 C++ 类模板

我有一个模板和一个专门化定义如下:

template<typename T>
struct SomeTemplate final
{
};

template<>
struct SomeTemplate<int> final
{
};

int main()
{
    SomeTemplate<int> test; // <-- error
}
Run Code Online (Sandbox Code Playgroud)

使用 Visual C++ 2012 编译出现以下错误:

error C2913: explicit specialization; 'SomeTemplate<T>' is not a specialization of a class template
    with
    [
        T=int
    ]
Run Code Online (Sandbox Code Playgroud)

当我删除时它编译得很好并且做正确的事情

  • 说明final
  • 来自template<>专业化

第一种情况对我来说有一定意义,因为它很可能final也限制了模板的专业化(而不仅仅是继承)。第二种情况对我来说有点奇怪,因为我认为这应该是一个语法错误。

这种行为正确吗?

c++ template-specialization visual-c++-2012

5
推荐指数
1
解决办法
1063
查看次数

错误:找不到“freetype6.dll”

最近我在使用 MonoGame Content Pipeline 工具时遇到了一些麻烦,无法加载纹理。错误消息表示找不到“freeimage.dll”。我在 MonoGame 论坛上查找了解决方案,最后下载了 64 位版本的 Visual C++ Redistributable Package 2012。这解决了我的问题,内容管道可以再次加载 .png 文件。现在管道工具在加载 .spritefont 文件时遇到问题。它说缺少“freetype.dll”。所有这些丢失的 .dll 文件是怎么回事?我刚刚下载了 VC++ Redistributable Package,但它只修复了纹理,而不修复字体。


更新:

我尝试下载 Visual C++ Redistributable Package 2017。但是,问题仍然存在......

c# visual-c++ monogame content-pipeline visual-c++-2012

5
推荐指数
1
解决办法
4003
查看次数