• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Conny14156

DX11
An Invalid parameter was passed to the returning function?

8 posts in this topic

Hi, Am trying to follow
http://www.braynzarsoft.net/index.php?p=D3D11BD
This tutorial but I keep getting
An Invalid parameter was passed to the returning function.
When my code try to run
hr = D3d11Device->CreateVertexShader(VSBuffer->GetBufferPointer(), VSBuffer->GetBufferSize(), NULL, &VS);
I get a error message saying that An Invalid parameter was passed to the returning function and am not sure why :(
Thank you if you could explain it to me I also copy pasted my code in here if it was needed


[CODE]
#include <Windows.h>
#include <d3d11.h>
#include <D3DX11.h>
#include <D3DX10.h>
#include <xnamath.h>
#include <DxErr.h>
#pragma comment(lib, "DXErr.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
bool InitializeWindow(HINSTANCE hInstance,int showWnd,int windowWidth, int windowHeight,bool windowed);
int messageLoop();
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);

HRESULT hr;
HWND hWnd = NULL;
const int windowWidth = 800;
const int windowHeight = 600;
//3DirectX
bool InitDirect3D11App(HINSTANCE hInstance);
void ReleaseObjects();
bool InitScene();
void UpdateScene();
void DrawScene();

IDXGISwapChain* SwapChain;
ID3D11Device* D3d11Device;
ID3D11DeviceContext* D3d11DevCon;
ID3D11RenderTargetView* renderTargetView;
ID3D11Buffer* TriangleVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob* VSBuffer;
ID3D10Blob* PSBuffer;
ID3D11InputLayout* VertLayout;
struct Vertex //Overloaded Vertex Structure
{
Vertex(){}
Vertex(float x, float y, float z)
: pos(x,y,z){}
XMFLOAT3 pos;
};
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE(layout);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,LPSTR lpCmnLine, int nShowCmd)
{
if(!InitializeWindow(hInstance,nShowCmd,windowWidth,windowHeight,true))
{
MessageBox(0,"Window Initilize Failed","Error",MB_OK);
return 0;
}
if(!InitDirect3D11App(hInstance))
{
MessageBox(0,"DirectX Init Failed","Error",MB_OK);
return 0;
}
if(!InitScene())
{
MessageBox(0,"Scene Init Failed","Error",MB_OK);
return 0;
}
messageLoop();
ReleaseObjects();
return 0;
}
int messageLoop()
{
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);

}
else
{
UpdateScene();
DrawScene();
}
}
return (int) msg.wParam;
}
bool InitializeWindow(HINSTANCE hInstance,int showWnd,int windowWidth, int windowHeight,bool windowed)
{

LPCTSTR WndClassName = "FusionEmptyWindowClass";
LPCTSTR windowTitleBar = "Fusion Empty:Placement Phase";
WNDCLASSEX wc;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
wc.lpszMenuName = NULL;
wc.lpszClassName = WndClassName;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Error Registering The Window Class","Error",MB_OK | MB_ICONERROR);
return 0;
}
hWnd = CreateWindowEx
(
NULL,
WndClassName,
windowTitleBar,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
MessageBox(NULL, "Error creating window",
"Error", MB_OK | MB_ICONERROR);
return 0;
}
ShowWindow(hWnd,showWnd);
UpdateWindow(hWnd);
return true;
}
bool InitDirect3D11App(HINSTANCE hInstace)
{
//Buffer describer
DXGI_MODE_DESC BufferDesc;

ZeroMemory(&BufferDesc,sizeof(DXGI_MODE_DESC));
BufferDesc.Width = windowWidth;
BufferDesc.Height = windowHeight;
BufferDesc.RefreshRate.Numerator= 60;
BufferDesc.RefreshRate.Denominator= 1;
BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;


//Describe our SwapChain
DXGI_SWAP_CHAIN_DESC SwapChainDesc;

ZeroMemory(&SwapChainDesc,sizeof(DXGI_SWAP_CHAIN_DESC));

SwapChainDesc.BufferDesc = BufferDesc;
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.BufferCount = 2;
SwapChainDesc.OutputWindow = hWnd;
SwapChainDesc.Windowed = true;
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

//Creating the SwapChain
hr = D3D11CreateDeviceAndSwapChain
(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,NULL,NULL,NULL,
D3D11_SDK_VERSION,
&SwapChainDesc,
&SwapChain,
&D3d11Device,
NULL,
&D3d11DevCon
);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),TEXT("D3D11CreateDeviceAndSwapChain"),MB_OK);
return 0;

}
//BackBuffer Creating
ID3D11Texture2D* BackBuffer;
hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
if(FAILED(hr))
{
MessageBox(NULL, DXGetErrorDescription(hr),TEXT("SwapChain->GetBuffer"), MB_OK);
return 0;
}
//Rendering Target
hr = D3d11Device->CreateRenderTargetView(BackBuffer,NULL,&renderTargetView);
BackBuffer->Release();
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),TEXT("D3d11Device->CreateRenderTargetView"),MB_OK);
return 0;
}
//Targeting Render target
D3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL ); // <----------------- SET NOT GET!!!!!!
//Set the target
return true;

}
bool InitScene()
{

[size=5][u][b]//Compile Shaders from shader file 5 or 4 = VERSION
hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, 0, &VSBuffer, 0, 0);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3DX11CompileFromFile",MB_OK);
}
hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &VSBuffer, 0, 0);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3DX11CompileFromFile",MB_OK);
}[/b][/u][/size]

//Create the Shader Objects
//The problem
hr = D3d11Device->CreateVertexShader(VSBuffer->GetBufferPointer(), VSBuffer->GetBufferSize(), NULL, &VS);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3d11Device->CreateVertexShader",MB_OK);
}
hr = D3d11Device->CreatePixelShader(PSBuffer->GetBufferPointer(), PSBuffer->GetBufferSize(), NULL, &PS);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3d11Device->CreatePixelShader",MB_OK);
}
//Set Vertex and Pixel Shaders
D3d11DevCon->VSSetShader(VS, 0, 0);
D3d11DevCon->PSSetShader(PS, 0, 0);
//Create the vertex buffer
Vertex v[] =
{
Vertex( 0.0f, 0.5f, 0.5f ),
Vertex( 0.5f, -0.5f, 0.5f ),
Vertex( -0.5f, -0.5f, 0.5f ),
};
D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof( Vertex ) * 3;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA vertexBufferData;
ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = v;
hr = D3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &TriangleVertBuffer);
//Set the vertex buffer
UINT stride = sizeof( Vertex );
UINT offset = 0;
D3d11DevCon->IASetVertexBuffers( 0, 1, &TriangleVertBuffer, &stride, &offset );
//Create the Input Layout
hr = D3d11Device->CreateInputLayout( layout, numElements, VSBuffer->GetBufferPointer(),
VSBuffer->GetBufferSize(), &VertLayout );
//Set the Input Layout
D3d11DevCon->IASetInputLayout( VertLayout );
//Set Primitive Topology
D3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
//Create the Viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = windowWidth;
viewport.Height = windowHeight;
//Set the Viewport
D3d11DevCon->RSSetViewports(1, &viewport);

return true;
}
void UpdateScene()
{

}
void DrawScene()
{
float bgColor[4] = {(0.0f, 0.0f, 0.0f, 0.0f)};
D3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);
D3d11DevCon->Draw( 3, 0 );
SwapChain->Present(0,0);
}
void ReleaseObjects()
{
//Window Release
SwapChain->Release();
D3d11Device->Release();
D3d11DevCon->Release();
//Rendering Release
TriangleVertBuffer->Release();
VS->Release();
PS->Release();
VSBuffer->Release();
PSBuffer->Release();
VertLayout->Release();

}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
{
if(wParam == VK_ESCAPE)
{
if(MessageBox(0,"Are you sure you want to Quit","Really", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
DestroyWindow(hWnd);
}
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;

}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
[/CODE]
0

Share this post


Link to post
Share on other sites
I've noticed it is possible to successfully compile a shader into object code (array of DWORDs) and still have CreateVertexShader() fail with INVALID_PARAMETER if the original shader had invalid numbers of instructions, samplers, constants, etc.

What does the shader you are submitting look like? Edited by Steve_Segreto
0

Share this post


Link to post
Share on other sites
Look like this :3

float4 VS(float4 inPos : POSITION) : SV_POSITION
{
return inPos;
}
float4 PS() : SV_TARGET
{
return float4(0.0f, 0.0f, 1.0f, 1.0f);
}
0

Share this post


Link to post
Share on other sites
Perhaps your hardware simply doesn't support shader model 5?

Create the D3D11 device with the debug layer enabled (D3D11_CREATE_DEVICE_DEBUG device flag). This should give you more insight as to what could be wrong. Edited by eppo
0

Share this post


Link to post
Share on other sites
I also tried version 4, but it gave me the same error and I tried both on my lappy and station computer, my laptop should support version 5, cause atleast that what google said >.<, But I will try the Debug flag tommorow,unable to do it at the moment :( Edited by Conny14156
0

Share this post


Link to post
Share on other sites
[quote name='eppo' timestamp='1354055062' post='5004704']
Perhaps your hardware simply doesn't support shader model 5?

Create the D3D11 device with the debug layer enabled (D3D11_CREATE_DEVICE_DEBUG device flag). This should give you more insight as to what could be wrong.
[/quote]
This may seems a stupid question but is this the correct way?
hr = D3D11CreateDeviceAndSwapChain
(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
NULL,
NULL,
D3D11_SDK_VERSION,
&amp;SwapChainDesc,
&amp;SwapChain,
&amp;D3d11Device,
NULL,
&amp;D3d11DevCon
);

I get no "compiler error" when I do this but nothing else really changed o.o Edited by Conny14156
0

Share this post


Link to post
Share on other sites
I tested a few things today and it seems like D3d11Device->CreatePixelShader somehow is the source of my problem, am not sure why but if I remove this my compiler doesnt complains any more about the CreateVertexShader but something else. Is it possible that the PixelShader returns onto the vertex and thus creating the problem? or is it cause I have DxErr included? I notice that in the the tutorial source file he does not have it cause it looks cleaner that way, but is it also the cause of my error?
0

Share this post


Link to post
Share on other sites
[quote name='Stuntdk' timestamp='1354169683' post='5005204']
When you compile your pixelshader you are providing a pointer to the Vertexbuffer rather than the Pixelbuffer.
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;VSBuffer, 0, 0);[/source]
Should be:
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;PSBuffer, 0, 0);[/source]
[/quote]

Yeha I noticed that to early today, biggest fail ever :(. but thank you :3. Edited by Conny14156
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By YixunLiu
      Hi,
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
       
      Thanks.
       
      YL
       
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
      Thanks!
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
    • By ProfL
      Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.
  • Popular Now