_com_error exception on DirectX Create* methods - c++

I have been trying to get into DirectX programming lately (with C++/Win32), and I encountered some issues.
A friend programmed a very simple random terrain generator that works with Perlin Noise, so I tried to grab his code and make a DirectX 11 renderer for it, but my program throws an "Microsoft C++ Exception", _com_error when I run it.
Even wierder, the program breaks at different lines of code depending on the build type...
On Debug, the program breaks on this chunk of code:
// Load the pixel shader
std::ifstream pixelFile("pixel.cso");
if (!pixelFile)
return false;
std::string pixelContents((std::istreambuf_iterator<char>(pixelFile)),
std::istreambuf_iterator<char>());
pixelFile.close();
if (FAILED(mpDevice->CreatePixelShader(pixelContents.c_str(),
pixelContents.size(),
NULL,
&mpPixelShader)))
return false;
And on Release:
// Create and set the input layout
if (FAILED(mpDevice->CreateInputLayout(layoutDescription,
layoutDescriptionSize,
vertexContents.c_str(),
vertexContents.length(),
&mpVertexLayout)))
return false;
mpPixelShader is a member of type ID3D11PixelShader*, and mpVertexLayout is a member of type ID3D11InputLayout*.
Of course, the first thing I thought when I saw that the error was different was checking for memory corruption, and sure enough I found one in my friend's code after running ApplicationVerifier and setting the _crtDbgFlag, but it is fixed now and I still have this error...
The application ran fine when the rendering initialization function was filled with a modified version of the one found on the MSDN Win32 DirectX Triangle Tutorial too.

The cso file is not a text, it is a binary file. A std::string will not work, the file will contains bytes that are 0.

Related

OpenCV DirectX 11 Interoperability

I need to read an image in OpenCV, send it to DirectX, do some processing, and then send the output image back to OpenCV. I am completely new to this, and was working with DirectX 11, therefore, I decided to refer this sample which demonstrates OpenCV and DirectX interoperability. There are options for both GPU and CPU modes, but right now, I plan to use only the CPU. The program builds without any errors, but returns the following runtime error everytime:
Exception thrown at 0x0000000000000000 in Direct3D Win32 my_project_name.exe: 0xC0000005: Access violation executing location 0x0000000000000000. occurred
I looked for solutions everywhere but couldn't find any. Since this is a sample, I guess many people might have used this.
Here are the lines where I'm getting an exception.
if (cv::ocl::haveOpenCL())
{
m_oclCtx = cv::directx::ocl::initializeContextFromD3D11Device(m_pD3D11Dev); //this is the line which throws the exception
}
m_oclDevName = cv::ocl::useOpenCL() ?
cv::ocl::Context::getDefault().device(0).name() :
"No OpenCL device";
On hovering the cursor above m_pD3D11Dev, this message is displayed by the intellisense:
m_pD3D11Dev | 0x000001f5a286c618 <No type information available in symbol file for d3d11.dll>
I am guessing that there is some error in my setup or some other linker error since this is a sample code provided by OpenCV(which i am assuming is obviously going to run). Any help or guidance would be appreciated.
I'm using DirectX 11 and OpenCV 3.4.4 to build(x64) this in Visual Studio 19. I also tried building(x64) it in Visual Studio 17, but the results were same.
Thanks in advance.

Running the executable of hdl_simple_viewer.cpp from Point Cloud Library

The Point Cloud library comes with an executable pcl_hdl_viewer_simple that I can run (./pcl_hdl_viewer_simple) without any extra arguments to get live data from a Velodyne LIDAR HDL32.
The source code for this program is supposed to be hdl_viewer_simple.cpp. A simplified version of the code is given on this page which cannot be compiled readily and requires a tiny bit of tweaking to make it compile.
My problem is that the executable that I build myself for both the versions are not able to run. I always get the smart pointer error "Assertion px!=0" error. I am not sure if I am not executing the program in the correct way or what. The executable is supposed to be executed like
./hdl_viewer_simple -calibrationFile hdl32calib.xml -pcapFile file.pcap
in case of playing from previously recorded PCAP files or just ./hdl_viewer_simple if wanting to get live data from the real sensor. However, I always get the assertion failed error.
Has anyone been able to run the executables? I do not want to use the ROS drivers
"Assertion px!=0" is occurring because your pointer is not initialized.
Now that being said, you could initialize it inside your routines, in case the pointer is NULL, especially for data input.
in here, you can try updating the line 83 like this :
CloudConstPtr cloud(new Cloud); //initializing your pointer
and hopefully, it will work.
Cheers,

Freeglut crashes after scanf in W8.1 and VS2012

I'm finishing a project for college in C using freeglut (2.8.1), GLEW 1.10.0, Visual Studio 2012 and Windows 8.1. It's nearly done but for some reason I can't read from console after something has been drawn.
For example, I draw something and then ask the user for a file to read, with new data to draw:
printf("File to read: ");
gets(fname); //with scanf the result is the same
printf("%s", fname); //just for testing
This prints the correct file name to the command line, and it reads the file correctly, however, for some reason, before the new data is displayed the entire thing crashes with the following error:
Unhandled exception at 0x73D3FB6D (freeglut.dll) in CV_TP1.exe: 0xC0000005: Access violation writing location 0x000000D4.
If I remove the gets/scanf and hard-code the file name the program works correctly. The same if I try to read something before all the openGL initializations, right at the top of the main function.

Access Violation exception when running a release-built application

Recently I have been developing a small OpenGL game. Everything in it runs fine with the debug build but when I build the release, I get a strange Access Violation exception.
I searched across the code and it seems that the problem occurs when I try to open a file. Here is the function where I think the problem is coming from:
#define LOCAL_FILE_DIR "data\\"
#define GLOBAL_FILE_DIR "..\\data\\"
std::string FindFile(const std::string &baseName)
{
std::string fileName = LOCAL_FILE_DIR + baseName;
std::ifstream testFile(fileName.c_str()); // The code breaks here
if(testFile.is_open())
return fileName;
fileName = GLOBAL_FILE_DIR + baseName;
testFile.open(fileName.c_str());
if(testFile.is_open())
return fileName;
throw std::runtime_error("Could not find the file " + baseName);
}
This code is associated with loading of GLSL shaders. A function takes the shader's file name and then passes it to FindFile in order to find the file needed.
Just as a general rule from personal (and teaching) experience: >90% of the cases where Debug works fine and Release crashes are due to uninitialized variables. That's a little harder to do in C++ than in C, but it is a very common problem. Make sure all your vars (like baseName) are initialized before using them.
I fixed the problem.
Everything was happening because I have made the Release build using glsdk's Debug build libraries. Changing to the Release build libraries fixed the problem.
Check that baseName is valid. Try printing it out. You may be getting a corrupted copy of baseName or your stack may have gotten trashed prior to that point (same result).

Boost serialization assertion fail

I use boost's binary serialization and it worked well until now. I have std::list of pointers to serialize for output (oarchive) but serialization fails inside object's serialize() function with MSVC's dialog:
R6010 -abort() has been called
and such string is printed into console window:
Assertion failed: 0 == static_cast<int>(t) || 1 == static_cast<int>(t), file c:\program files\boost\boost_1_44\boost\archive\basic_binary_oprimitive.hpp, line 91
what does it mean?
Project is pretty big, sources are distributed so I cannot post it's code here, but I tried to simulate this error within simple project - there it works fine what is strange.
P.S. I use boost 1.44 with MSVC2010EE on Windows XP. When I click "retry" on "Debug Error!" window debugger shows arrow on the code line next to serialization archive << myList; line - I mean it seems like error occurred at some destructor or something.
When I make changes inside objects serialize() function - they will be applied just when I rebuild whole project (clean before compiling) - but if I just compile it (where IDE shows that all sources which include changed header are recompiled) - no changes will happen at runtime since last version (I tried with printf()) - that's strange.
Could I occasionally set some critical definitions or something?
The line in question says:
// trap usage of invalid uninitialized boolean which would
// otherwise crash on load.
It looks like at some point you are trying to serialize a bool that hasn't been initialized. Without further code we can't help you find which one.