Jump to content

  • Log In with Google      Sign In   
  • Create Account


An Invalid parameter was passed to the returning function?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Conny14156   Members   -  Reputation: 259

Like
0Likes
Like

Posted 27 November 2012 - 03:37 PM

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


#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);
}


Sponsor:

#2 Steve_Segreto   Crossbones+   -  Reputation: 1514

Like
0Likes
Like

Posted 27 November 2012 - 04:12 PM

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, 27 November 2012 - 04:12 PM.


#3 Conny14156   Members   -  Reputation: 259

Like
0Likes
Like

Posted 27 November 2012 - 04:12 PM

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);
}

#4 eppo   Crossbones+   -  Reputation: 2367

Like
0Likes
Like

Posted 27 November 2012 - 04:24 PM

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, 27 November 2012 - 04:25 PM.


#5 Conny14156   Members   -  Reputation: 259

Like
0Likes
Like

Posted 27 November 2012 - 04:53 PM

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, 27 November 2012 - 06:38 PM.


#6 Conny14156   Members   -  Reputation: 259

Like
0Likes
Like

Posted 28 November 2012 - 07:07 AM

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.

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, 28 November 2012 - 09:18 AM.


#7 Conny14156   Members   -  Reputation: 259

Like
0Likes
Like

Posted 28 November 2012 - 06:34 PM

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?

#8 Stuntdk   Members   -  Reputation: 428

Like
3Likes
Like

Posted 29 November 2012 - 12:14 AM

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, &VSBuffer, 0, 0);[/source]
Should be:
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &PSBuffer, 0, 0);[/source]

#9 Conny14156   Members   -  Reputation: 259

Like
0Likes
Like

Posted 29 November 2012 - 10:25 AM

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]


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

Edited by Conny14156, 29 November 2012 - 10:27 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS