I upgraded a project from VS2012 to VS2013, the release version works correctly but the debug version fails on an assert.
Before main
I slowly watch the RegisterCategory
exceed the max number of categories. Stepping through the debugger they all seem like reasonably titled categories, and then the thing fails the assert.
Confusingly, functions in atltrace.h
such as the following appear to be called more than once. With different function addresses, I suppose this wouldn't be a problem if not for the 32 limit.
__declspec(selectany) CTraceCategoryEx<CTraceCategoryEx<>::TraceISAPI> atlTraceISAPI(_T("atlTraceISAPI"));
Whats going on? Can I disable atltrace?
static void RegisterCategory(_In_z_ LPCTSTR pszCategory, unsigned int nCategory)
{
if (pszCategory == nullptr)
{
return;
}
if (m_nLastCategory >= MaxCategoryArray)
{
ATLASSERT(false && "Too many categories defined");
return;
}
m_nMap[m_nLastCategory].nCategory = nCategory;
#ifdef _UNICODE
wcscpy_s(m_nMap[m_nLastCategory].categryName, MaxLengthOfCategoryName - 1, pszCategory);
#else
wchar_t buffer[MaxLengthOfCategoryName] = { 0 };
swprintf_s(buffer, MaxLengthOfCategoryName - 1, L"%S", pszCategory);
wcscpy_s(m_nMap[m_nLastCategory].categryName, MaxLengthOfCategoryName - 1, buffer);
#endif
m_nLastCategory++;
}
Linker 2012 (working)
/OUT:"C:\Users\kandel\Desktop\obfuscated\x64\Debug\\mine.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Users\kandel\Desktop\obfuscated\x64\Debug\mine.pdb" /DYNAMICBASE "C:\Users\kandel\Desktop\fslim\\glew\glew-1.9.0\lib\glew32.lib" "C:\Users\kandel\Desktop\fslim\\glew\glew-1.9.0\lib\glew32mx.lib" "C:\Users\kandel\Desktop\fslim\\Andor SDK3\atcorem.lib" "BNSPCIeBoard.lib" "cudart.lib" "cuda.lib" "WINMM.lib" "libgmp-10.lib" "libtiff.lib" "qtmaind.lib" "Qt5Cored.lib" "Qt5Guid.lib" "Qt5OpenGLd.lib" "Qt5PrintSupportd.lib" "opengl32.lib" "glu32.lib" "Qt5Widgetsd.lib" "opencv_core300d.lib" "opencv_cuda300d.lib" "opencv_cudaarithm300d.lib" "opencv_cudaimgproc300d.lib" /DEBUG /MACHINE:X64 /PGD:"C:\Users\kandel\Desktop\obfuscated\x64\Debug\mine.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\SLIM4.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Qt\5.2.1\msvc2012_64_opengl\lib" /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\lib\x64" /TLBID:1
VS 2013 Not Working
/OUT:"C:\Users\QLI\Desktop\obfuscated\x64\Debug\\mine.exe" /MANIFEST:NO /NXCOMPAT /PDB:"C:\Users\QLI\Desktop\obfuscated\x64\Debug\mine.pdb" /DYNAMICBASE "C:\Users\QLI\Desktop\obfuscated\\Andor SDK3\atcorem.lib" "BNSPCIeBoard.lib" "cudart.lib" "cuda.lib" "WINMM.lib" "libgmp-10.lib" "libtiff.lib" "qtmaind.lib" "Qt5Cored.lib" "Qt5Guid.lib" "Qt5OpenGLd.lib" "Qt5PrintSupportd.lib" "opengl32.lib" "glu32.lib" "Qt5Widgetsd.lib" "opencv_core300d.lib" "opencv_cuda300d.lib" "opencv_cudaarithm300d.lib" "opencv_cudaimgproc300d.lib" /DEBUG /MACHINE:X64 /PGD:"C:\Users\QLI\Desktop\obfuscated\x64\Debug\mine.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\mine.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\lib" /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\lib\x64" /TLBID:1
The principle difference between these two is that in VS2012 I could choose no atl
and everything ran well/correctly, wherein in VS2013 I can't choose this option.
--edit--
I removed all externals libraries except Qt and CUDA. Noticed that removing #include <afxwin.h>
from the precompiled header makes the problem go away, although I need to use afxwin.h
...
I was able to get around the problem by moving the afx
portion of my code into a dll and removing the header. Why this functionality changed between VS version is a lingering question. I can only conclude the MS broke my code by changing the max numbers that can be registered.