"Could not initialize Direct3d" - directx

I am trying to run an exe from this Directx-11 tutorial website:tutorial5 (exe at the end of the page), but I get the error "Could not initialize Direct3d".
I get the same error when I download the solution and run it on Visual Studio 2013 or Visual Studio 2010.
I have installed the latest DirectX (installed using "DirectX
End-User Runtime Web Installer":
link)
I also installed DirectX 9 SDK from here: DirectX 9 SDK June
2010
dxdiag shows Direct3d "Enabled".
I updated the "Intel HD Graphics library on core i5" to the latest driver.
What am I missing? How can I run Directx-11 applications on my machine?
Thanks!

The error happened here, you should check the result of Initialize function to see what's the error.
// Initialize the Direct3D object.
result = m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if(!result)
{
MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
return false;
}
Another useful tip is to turn on DEBUG mode when create device and swap chain. Try the following code the enable debug mode when creating device(in d3dclass.cpp, add the following code before calling D3D11CreateDeviceAndSwapChain, and don't forget to set the third parameter of this function to flags)
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// Create the swap chain, Direct3D device, and Direct3D device context.
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, flags, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if(FAILED(result))
{
return false;
}
Build and run the program in debug mode and see the output in VS's output window.

Related

C# PInvoke returning invalid/wrong bool value, only when native code compiled in debug mode (OSX only)

So, I have a weird issue. I am doing a simple PInvoke call to get a boolean from managed code.
C/C++
Q_DECL_EXPORT bool net_variant_getBool(NetVariantContainer* container)
{
bool result = container->variant->getBool();
// This function will only return the right value if I use the following code in OSX in release mode (debug works with or without it).
// qDebug("Return value is: %d", result);
return result;
}
C#
[DllImport("QmlNet.dylib")]
static extern bool net_variant_getBool(IntPtr variant);
The code above, as is, works perfectly on Linux/Windows in either debug or release mode, and OSX in debug mode only.
On OSX in release mode, the resulting value in C# is wrong. If I attempt to log what the returning bool is (to figure out the issue), it prints out the right value, and then the right value is returned! That's right, the qDebug macro above that is commented out will fix my issue if compiled in. Wth?
This problem only presents it's self in Release mode on OSX/clang.
Here is the compilation output on OSX for both debug and release builds. https://gist.github.com/pauldotknopf/3949b7e86d6a4bfb59788dd0b7c44536
I'm utterly lost. Anybody have any ideas? I don't want to ship debug libs!
It turns out that bool is a non-blittable type and can't be used as a return value. See here.
I changed my code to return a byte instead.

How to solve this error? APP debugging

I don't know what this error means:
Assert failed: Unsupported format for depth and stencil buffers...
I faced the same problem today when I was porting form cocos2d-x v3.4 to v3.14. There was some difference in appDelegate.
try this
in AppDelegate.h declare this method.
virtual void initGLContextAttrs();
in AppDelegate.cpp
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLView::setGLContextAttrs(glContextAttrs);
}
// if you want to use the package manager to install more packages,
// don't modify or remove this function
static int register_all_packages()
{
return 0; //flag for packages manager
}
see if this resolves the issue. It did the trick for me.
It shows the issue is with the eaglview you are creating,can you please paste the appcontroller and appdelegate content here as the error comes by running the content in applicationdidfinishlaunching function placed in appcontroller.
and which Cocos2dx version you are using?

Does C# spec permit casting from a ulong to an int? Monotouch gives a NumberOverflow

I tested the following code in several environments
ulong c = 10000000000000000; // Base 10
int w = (int) c; // w should be 1874919424
The results are as follows:
VS2013 .NET 4.5 - w = 1874919424
Xamarin (mono) Android - w = 1874919424
Xamarin (mono) iOS - number overflow
Is this an issue that Xamarin should/will fix? (e.g. the C# spec requires it)
Does iOS / Objective C code support this casting? (why isn't this working?)
How can I work around this, without boxing or decreasing performance?
This method is used extensively in BouncyCastle encryption and I'm porting this to C# and want to make as few changes as necessary.
If compiled identically then the behaviour should be identical on all platforms and that should not be related to unified/classic 32/64bits or nint support.
So make sure your iOS project is not build with the Generate overflow checks enabled.
Look for this in Project Options, Build, Compiler in Xamarin Studio or in the command-line options given to the compiler: /checked.

OpenCV249 crashes after initializing camera capture on Windows 7

I have got a problem with running my opencv app on windows 7. I used visual studio C++ 2012 on Windows 8.1 to compile it.
After compiling, everything is ok on Windows 8.1 but when i try to launch it on a laptop with Windows 7 it initializes the camera(blue led next to the camera lights up) then crashes. I havent got any idea what am i doing wrong.
Here is the code:
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
int main( void )
{
cvNamedWindow("TEST" ,cv::WINDOW_NORMAL);
cv::VideoCapture capture;
cv::Mat frame;
capture.open( -1 );
if ( ! capture.isOpened() )
{
printf("--(!)Error initializing the camera\n");
system("pause");
}
while(capture.read(frame))
{
cv::imshow( "TEST", frame );
}
return 0;
}
Thank You for help.
Ok guys. I figured out it may be the problem with the camera being not compatible with opencv249. Thats why it crashes while trying to initialize it. I replaced capture from camera with capture from file and everything went great.
I just wasnt smart enough to figure it out before spamming on forum, sorry.

[MonoTouch][Bass.dll] Application crash "Attempting to JIT compile method .. while running with --aot-only"

I faced a problem, that I can't solved for 3 days and you're my last hope.
My goal is to record sound with Bass.dll (there's special version of library for iPhone and version of .net wrapper for it; can be found here: un4seen.com)
On simulator program works (or seems to work properly). But when I tried to run it on the iPhone - I got this error:
"Attempting to JIT compile method '(wrapper native-to-managed) RecordingAudioHelloWorld.Player:recordingHandler (int,intptr,int,intptr)' while running with --aot-only."
error happens here:
RECORDPROC _recordingHandler = new RECORDPROC(recordingHandler);
_record = Bass.BASS_RecordStart(16000, 1, BASSFlag.BASS_SPEAKER_RIGHT, _recordingHandler, IntPtr.Zero); // <-- ERROR!!!
private int recordingHandler (int handle, IntPtr buffer, int length, IntPtr user)
{
//....
}
As I read here, on SO, I changed Linker behavior to "Link SDK assemblies only", but it has no effect.
Is there anything that I could do with it?
Try to add the MonoPInvokeCallback attribute to your recordingHandler function. Note that you also need to make the function static. YourDelegateType should be the delegate type you defined in C# that corresponds to the signature of this method.
[MonoPInvokeCallback (typeof(YourDelegateType)]
private static int recordingHandler (int handle, IntPtr buffer, int length, IntPtr user)
{
// ...
}

Resources