Skip to main content
gamedev.net
🔒 Locked

Logical Error

Started by Marlow Landscape 7 replies 750+ views
Original Post
Marlow Landscape
Marlow Landscape
I get one syntax error when I try to compile my app and I dunno how to fix it please take a look at the part:

/*********************************************************************
* Render 2
*********************************************************************/
void Render( )
{ //------------->219 syntax error before `{' token 
     IDirect3DSurface9* backbuffer = NULL;   //This will hold the backbuffer
     if(NULL == pd3dDevice) //Check if the Direct3D Device is valid
     return false;
     
     //clears the back buffer to a blue color
     pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
                       D3DCOLOR_XRGB( 0,0,255 ),1.0f, 0);

       //Get the BackBuffer
       pd3dDevice->GetBackBuffer( 0,
                                  0,
                                  D3DBACKBUFFER_TYPE_MONO,
                                  &backbuffer );
                               
    //Copy the offscreen surface to the backbuffer
    //Note the use of NULL values for the source and 
    //destination of RECTS
    //This ensures a copy of the entire surface to the BackBuffer                         
    pd3dDevice->StretchRect(bkgrd, NULL, backbuffer, NULL, D3DTEXF_NONE);
	if (hResult != D3D_OK)
		MessageBox(NULL,"failed", "error", MB_OK);
                             
     // Present the back buffer content to the display 
     pd3dDevice->Present( NULL, NULL, NULL, NULL);
}


This is not my full code this is just the render function that I get this one syntax error and I have tried alot of things :( Help is much appreciated. :) [Edited by - Marlow Landscape on January 12, 2005 1:55:50 PM]
"You have tried and failed miserably, the lesson is, never try"-Homer J. Simpson.
Marlow Landscape
Marlow Landscape
I mentioned with an arrow but well, nevermind I just fixed it it was missing a "{" token...
"You have tried and failed miserably, the lesson is, never try"-Homer J. Simpson.
Marlow Landscape
Marlow Landscape
Strange, I have put now the correct code but no image loads when I start the program, heres the code but more complete:
HRESULT CreateOffScreenPlainSurface(  //6 Parameters functionUINT Width,       //width and height of the surfaceUINT Height,D3DFORMAT Format, //D3DFORMAT TypeDWORD Pool,       //Memory poolIDirect3DSurface9 **ppSurface,    // Resulting surface pointerHANDLE* pHandle );   //Always NULLHRESULT hResult;IDirect3DSurface9* surface = NULL;hResult = CreateOffScreenPlainSurface(   //Now we just have to insert640,                                    //the value for each parameter480,                                   //we typed.D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&surface,NULL);if ( FAILED ( hResult ) )    return false;HRESULT D3DXLoadSurfaceFromFile(LPDIRECT3DSURFACE9 pDestSurface,CONST PALETTEENTRY* pDestPalette,CONST RECT* pDestRect,LPCTSTR pSrcFile,CONST RECT* pSrcRect,DWORD Filter,D3DCOLOR Colorkey,D3DXIMAGE_INFO* pSrcInfo);IDirect3DSurface9* Surface;hResult = D3DXLoadSurfaceFromFile( surface,                                   NULL,                                   NULL,                                   "Preview.bmp",                                   NULL,                                   D3DTEXF_NONE,                                   0,                                   NULL                                   );if ( FAILED( hResult ) )    return false;        HRESULT StretchRect(    IDirect3DSurface9 *pSourceSurface,    CONST RECT *pSourceRect,    IDirect3DSurface9 *pDestSurface,    CONST RECT *pDestRect,    D3DTEXTUREFILTERTYPE Filter    );/********************************************************************** Render*********************************************************************/}void render(void){         IDirect3DSurface9* backbuffer = NULL;   //This will hold the backbuffer     if(NULL == pd3dDevice) //Check if the Direct3D Device is valid     return;          //clears the back buffer to a blue color     pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,                       D3DCOLOR_XRGB( 0,0,255 ),1.0f, 0);       //Get the BackBuffer       pd3dDevice->GetBackBuffer( 0,                                  0,                                  D3DBACKBUFFER_TYPE_MONO,                                  &backbuffer );                                   //Copy the offscreen surface to the backbuffer    //Note the use of NULL values for the source and     //destination of RECTS    //This ensures a copy of the entire surface to the BackBuffer                              pd3dDevice->StretchRect(bkgrd, NULL, backbuffer, NULL, D3DTEXF_NONE);                                  // Present the back buffer content to the display      pd3dDevice->Present( NULL, NULL, NULL, NULL);}

It should load my image but it is not loading :(
"You have tried and failed miserably, the lesson is, never try"-Homer J. Simpson.
bit64
bit64
I'll admit, your code is very confusing to me. Why do you put the function definitions there?

Anyway, aren't you supposed to be passing the newly created surface returned by CreateOffscreenPlainSurface to the function D3DXLoadSurfaceFromFile?

Also, I don't know if this helps, but the documentation from the SDK on D3DXLoadSurfaceFromFile says:

"Writing to a non-level-zero surface will not cause the dirty rectangle to be updated. If D3DXLoadSurfaceFromFile is called and the surface was not already dirty (this is unlikely under normal usage scenarios), the application needs to explicitly call IDirect3DTexture9::AddDirtyRect on the surface."

And where is your surface titled "bkgrd" coming from? I never see it declared, and wouldn't you want to be using "surface" there instead?

This is meant to be constructive criticism, not an attack, but I think you should spend some more time learning programming in C++ before you tackle Direct3d. Again, please don't take offense by that, I just think it will help you in the long run.
Don't be afraid to be yourself. Nobody else ever will be.
Marlow Landscape
Marlow Landscape
Don't worry I understand you, and I am not a mad man and I created this thread for suggestions as you are doing, and as I mentioned before this is not the full code so bkgrd was declared I replaced by myself srcSurface parameter for bkgrd because srcSurface was givin' me a lot of trouble.I have like 3 or 4 headers for my main file and this is only like 1/6 of it, its just my render function with previous declarations but I accidentally put some of them in the top so it isnt shown and some were globals so I like to put 'em on top. :)
If bkgrd was undeclared I would not be able to compile the project so I just ask you to keep posting on this thread :), and I didn't understand what you meant with those dirty triangles but once again I am not mad :) please I just ask you to try to find any logical errors or a param that is missing for the surface to be loaded.
I am always open to suggestions.
"You have tried and failed miserably, the lesson is, never try"-Homer J. Simpson.
bit64
bit64
From the SDK:

IDirect3DDevice9::StretchRect will fail for any of the following:

Okay, well it seems to me that the surface you are creating with CreateOffScreenPlainSurface should be the one sent to D3DXLoadSurfaceFromFile like this:

//should be declared as a member var or global
IDirect3DSurface9 * pSurface = NULL;




CreateOffScreenPlainSurface(&pSurface, ....);
if(pSurface == NULL)
return some_error;
D3DXLoadSurfaceFromFile(pSurface, ...);


void Render(void)
{
//get your back buffer and stuff

pd3dDevice->StretchRect(pSurface, NULL, backbuffer, NULL, D3DTEXF_NONE);


}


Some caveats according to the SDK, StretchRect will not work if both surfaces are offscreen plain surfaces and stretching is involved. So if the resolution of your back buffer is not 640x480 then this should fail, if I am reading that correctly.


Hope this helps more than it hinders.
Don't be afraid to be yourself. Nobody else ever will be.
Marlow Landscape
Marlow Landscape
hmm I see...I get your point, but still please take a look at the full file(not the whole project)
Those bunch of headers I am not using them right now but I will later and they are not conflicting thank godness and hey you almost guessed my back buffer global :) IDirect3DSurface9* backbuffer = NULL; well if you have some better render code in mind please let me know cause this one was a damn mess for me to fix, I took this from my directX book but almost 100% of those codes I gotta make some changes for example like the book suggested for me to put like
if ( FAILED( hResult ) )
return NULL;
This resulted in many warnings so I replaced for this
if ( FAILED( hResult ) )
return false;
and this was a lot used well there are other changes as well, for example I inserted some GUI but I still dunno how to create like for example File->Properties then a new window comes if you know how to create this window I'd appreciate to know how to do so :) well enough, here's the code:(compiles but quite messy)
#include <windows.h>#include "main.h"// include directx9#include <d3d9.h>#include <d3dx9tex.h>#include <string>#include <d3dx9.h>#include <d3dx9mesh.h>#include <d3dx9xof.h>// global variablesHINSTANCE hInst;							// application instanceHWND wndHandle;		                       // application window handleHRESULT                 lastResult;LPDIRECT3D9             pD3D;LPDIRECT3DDEVICE9       pd3dDevice;IDirect3DSurface9*		bkgrd;IDirect3DSurface9* backbuffer = NULL;   //This will hold the backbuffer/*************************************************************************render function************************************************************************/void Render(void){     if(NULL == pd3dDevice)     return;//clears the back buffer to a blue color     pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,                       D3DCOLOR_XRGB( 0,0,255 ),1.0f, 0);                            // Present the back buffer content to the display      pd3dDevice->Present( NULL, NULL, NULL, NULL); }////////////////////////////////////////////// forward declarationsbool initDirect3D() {HRESULT hr;D3DPRESENT_PARAMETERS d3dpp;D3DDISPLAYMODE d3ddm;D3DCAPS9 d3dCaps;DWORD dwBehaviorFlags = 0;pD3D = NULL;pd3dDevice = NULL;// Create the DirectX objectif(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION)))return false;if( FAILED( pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) ){return false;}if( FAILED( hr = pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL,D3DRTYPE_SURFACE, D3DFMT_D16 ) ) ){if( hr == D3DERR_NOTAVAILABLE )return false;} if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps ) ) ){return false;}if( d3dCaps.VertexProcessingCaps != 0 )dwBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;elsedwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;// Fills a block of memory with zerosZeroMemory(&d3dpp, sizeof(d3dpp));d3dpp.Windowed = TRUE;                    //DirectX Window Properties,d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //When full screen wantedd3dpp.BackBufferFormat = D3DFMT_UNKNOWN; //change d3dpp.Windowed to d3dpp.BackBufferCount = 1;            //False and the BackBufferFormatd3dpp.BackBufferHeight = 480;         //to D3DFMT_X8R8G8B8.d3dpp.BackBufferWidth = 640; d3dpp.hDeviceWindow = wndHandle; if( FAILED( pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wndHandle,dwBehaviorFlags, &d3dpp, &pd3dDevice)))return false;return true;}/* Declare WindowsProcedure */LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);/* Make the classname into a global variable */char szClassName[] = "Game";HINSTANCE hThisInstance;int WINAPI WinMain( HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil ){    HWND hwnd;               /* This is the handle for our window */    MSG messages;            /* Here messages to the application is saved */    WNDCLASSEX wincl;        /* Datastructure for the windowclass */    HMENU menu;              /* Handle of the menu */    /* The Window structure */    wincl.hInstance = hThisInstance;    wincl.lpszClassName = szClassName;    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */    wincl.style = CS_HREDRAW | CS_VREDRAW;             wincl.cbSize = sizeof(WNDCLASSEX);    /* Use default icon and mousepointer */    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);    wincl.lpszMenuName = NULL; /* No menu */    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */    wincl.cbWndExtra = 0;                      /* structure or the window instance */    /* Use lightgray as the background of the window */    wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);    /* Register the window class, if fail quit the program */    if(!RegisterClassEx(&wincl)) return 0;    /* The class is registered, lets create the program*/    hwnd = CreateWindowEx(           0,                   /* Extended possibilites for variation */           szClassName,         /* Classname */           "Game",         /* Title Text */           WS_OVERLAPPEDWINDOW, /* defaultwindow */           CW_USEDEFAULT,       /* Windows decides the position */           CW_USEDEFAULT,       /* where the window end up on the screen */           600,                 /* The programs width */           480,                 /* and height in pixels */           HWND_DESKTOP,        /* The window is a childwindow to desktop */           NULL,                /* No menu */           hThisInstance,       /* Program Instance handler */           NULL                 /* No Window Creation data */           );    /* Make the window visible on the screen */    ShowWindow(hwnd, nFunsterStil);    menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));    SetMenu(hwnd, menu);     /* Run the nessageloop. It will run until GetMessage( ) returns 0 */     MSG msg;     ZeroMemory( &msg, sizeof( msg ));     while( msg.message!=WM_QUIT)    if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )    {        TranslateMessage( &msg );        DispatchMessage ( &msg );    }    else    {        Render( );    }    return messages.wParam;    void cleanUp (void);    {         // Release the device and the Direct3D object         if( pd3dDevice != NULL )         {         pd3dDevice->Release( );         }         if(pD3D != NULL)         {pD3D->Release( );}}    /* insert surface file here*/    HRESULT CreateOffScreenPlainSurface(  //6 Parameters functionUINT Width,       //width and height of the surfaceUINT Height,D3DFORMAT Format, //D3DFORMAT TypeDWORD Pool,       //Memory poolIDirect3DSurface9 **ppSurface,    // Resulting surface pointerHANDLE* pHandle );   //Always NULLHRESULT hResult;IDirect3DSurface9* surface = NULL;hResult = CreateOffScreenPlainSurface(   //Now we just have to insert640,                                    //the value for each parameter480,                                   //we typed.D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&surface,NULL);if ( FAILED ( hResult ) )    return false;HRESULT D3DXLoadSurfaceFromFile(LPDIRECT3DSURFACE9 pDestSurface,CONST PALETTEENTRY* pDestPalette,CONST RECT* pDestRect,LPCTSTR pSrcFile,CONST RECT* pSrcRect,DWORD Filter,D3DCOLOR Colorkey,D3DXIMAGE_INFO* pSrcInfo);IDirect3DSurface9* Surface;hResult = D3DXLoadSurfaceFromFile( surface,                                   NULL,                                   NULL,                                   "./background.bmp",                                   NULL,                                   D3DTEXF_NONE,                                   0,                                   NULL                                   );if ( FAILED( hResult ) )    return false;        HRESULT StretchRect(    IDirect3DSurface9 *pSourceSurface,    CONST RECT *pSourceRect,    IDirect3DSurface9 *pDestSurface,    CONST RECT *pDestRect,    D3DTEXTUREFILTERTYPE Filter    );/********************************************************************** Render*********************************************************************/}void render(void){         IDirect3DSurface9* backbuffer = NULL;   //This will hold the backbuffer     if(NULL == pd3dDevice) //Check if the Direct3D Device is valid     return;          //clears the back buffer to a blue color     pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,                       D3DCOLOR_XRGB( 0,0,255 ),1.0f, 0);       //Get the BackBuffer       pd3dDevice->GetBackBuffer( 0,                                  0,                                  D3DBACKBUFFER_TYPE_MONO,                                  &backbuffer );                                   //Copy the offscreen surface to the backbuffer    //Note the use of NULL values for the source and     //destination of RECTS    //This ensures a copy of the entire surface to the BackBuffer                              pd3dDevice->StretchRect(bkgrd, NULL, backbuffer, NULL, D3DTEXF_NONE);                                  // Present the back buffer content to the display      pd3dDevice->Present( NULL, NULL, NULL, NULL);}/* The program returvalue is 0 - The value that PostQuitMessage( ) gave */LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){    switch (message)                  /* handle the messages */    {       case WM_COMMAND:           switch( wParam )           {      case WM_CLOSE:           DestroyWindow( hwnd );           return 0;      case WM_DESTROY:           PostQuitMessage (0);           return 0;                                        case IDM_OPTIONSVIDEOCONFIG:                    MessageBox (NULL, "Already on your game folder and soon available on the GUI also" , "VideoAdapter", 1);                 return 0;             case IDM_GAMEPLAY:                  case IDM_OPTIONSINPUT:             case IDM_FILESAVE:             case IDM_OPTIONSGFX:             case IDM_OPTIONSAUDIO:             case IDM_OPTIONSFULLSCREEN:                 MessageBox (NULL, "It shall be implemented in the next release" , "Sorry", 1);                 return 0;                  case IDM_FILEEXIT:                  SendMessage( hwnd, WM_CLOSE, 0, 0L );                  return 0;             case IDM_HELPABOUT:                  MessageBox (NULL, "Beta Version - 1.0 made by Destroyerz" , "About", 1);                  return 0;                               case IDM_FILEOPEN:                 OPENFILENAME ofn;                 char szFileName[MAX_PATH] = "";                 ZeroMemory(&ofn,sizeof(ofn));                 ofn.lStructSize = sizeof(ofn); // See note below                 ofn.hwndOwner = hwnd;                 ofn.lpstrFilter = "Saved Slot Files(*.ssf)\0*ssf\0All Files (*.*)\0*.*\0";                 ofn.lpstrFile = szFileName;                 ofn.nMaxFile = MAX_PATH;                 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;                 ofn.lpstrDefExt = "ssf";                 if(GetOpenFileName(&ofn))                 {                    // Do something with the file                 }    }break;           case WM_CLOSE:           DestroyWindow( hwnd );           return 0;      case WM_DESTROY:           PostQuitMessage (0);           return 0;      break;      default:                   /* for messages that we don't deal with */      return DefWindowProc(hwnd, message, wParam, lParam);   }  return 0;}

As you can see I have 2 render definitions, why not erase one?
because I have tried already and it almost f*cked up my code and took me time to put everything back on track, what I 'll probably do is to find some better render code and put it all on a clean window file and slowly insert my work there.
"You have tried and failed miserably, the lesson is, never try"-Homer J. Simpson.
Marlow Landscape
Marlow Landscape
O god now today I've inserted a mesh code, the project is fully clean but it loads no mesh and no background can someone at least pass me some more actual surface code?
"You have tried and failed miserably, the lesson is, never try"-Homer J. Simpson.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.