By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

Fun with constructors, inheritance

P: 15
Hello all, been a bit frustrated as of late with one of C++ programming projects. The problem goes like this:

I have a game engine-type thing going that has support for several different rendering APIs (not all simultaneously running, obviously, but you can switch between them at runtime with my console system.) Now in order for everything to play nice, I have a 'pipeline' class that acts as a layer of abstraction between the core engine update mechanics/other stuff it (engine) needs to do, like sound, input, so on, so forth. My problem boils down to this: When the CreateAPIInterface() message is sent to my pipeline class, it requests the setting corresponding to what rendering API should be used. This executes fine, however once it receives/parses the requested string, it *should* instantiate a new, dynamically-allocated instance of a derived renderer class tailored to use one of the four supported paths (DirectX9, 10, OpenGL 2.1, 3.0) Problem is, the 'new' instruction never completes. I can step through (using MSVC++ 2005) my program with the debugger and it just putzes out. No jumping to malloc.c, no heap allocation, nothing. Just putters out entirely. This has me frustrated beyond belief as I have never seen anything of the sort. On top of it all, C++ was supposed to eliminate this kind of oddity, as I understand it. Anyone have any advice/suggestions? I can provide code upon request, I didn't attach it off the bat due to size concerns.
Aug 12 '07 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Show me the code from the function arguments to where the instantiation should occur.
Aug 12 '07 #2

P: 15
Expand|Select|Wrap|Line Numbers
  1. #ifdef _WINDOWS
  2. bool CRenderPipeline::CreateAPIInterface(HWND hWnd)
  3. {
  4.     if(settingsManager->GetVar("r_renderPath") == "DIRECT3D9")
  5.     {
  6.         MessageBox(NULL, L"Direct3D9 mode activated!", L"", MB_OK);
  7.         renderInterface = new CRendererDX9;
  8.  
  9.         renderInterface->InitializeGraphicsSubsystem(hWnd, settingsManager);
  10.     }
  11.     else if(settingsManager->GetVar("r_renderPath") == "DIRECT3D10")
  12.     {
  13.         MessageBox(NULL, L"Direct3D10 mode activated!", L"", MB_OK);
  14.         // renderInterface = new CRendererDX10(hWnd, settingsManager);
  15.     }
  16.     else if(settingsManager->GetVar("r_renderPath") == "OPENGL2.1")
  17.     {
  18.         // renderInterface = new CRendererOGL21();
  19.         return false;
  20.     }
  21.     else if(settingsManager->GetVar("r_renderPath") == "OPENGL3.0")
  22.     {
  23.         // renderInterface = new CRendererOGL30();
  24.         return false;
  25.     }
  26.     else
  27.     {
  28.         return false;
  29.     }
  30.     if(renderInterface)
  31.     {
  32.         InitializeOverlayInterface();
  33.         return true;
  34.     }
  35.     else
  36.     {
  37.         return false;
  38.     }
  39. }
  40.  


CRendererDX9 class implementation:
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3. #include "Renderer.h"
  4.  
  5. // DirectX stuff
  6. #include "DirectX\d3d9.h"
  7. #include "Windows.h"
  8. #pragma comment (lib, "DirectX/libs/d3d9.lib")
  9.  
  10. class CRendererDX9 : public Renderer
  11. {
  12. public:
  13.     ~CRendererDX9()
  14.     {
  15.     }
  16.  
  17.     forceinline void DrawFrame()
  18.     {
  19.         d3dDeviceInterface->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  20.  
  21.         d3dDeviceInterface->BeginScene();
  22.         d3dDeviceInterface->EndScene();
  23.  
  24.         d3dDeviceInterface->Present(NULL, NULL, NULL, NULL);
  25.     }
  26.  
  27.     bool InitializeGraphicsSubsystem(HWND &targetWindow, CEngineSettingsManager* settings)
  28.     {
  29.         MessageBox(NULL, L"Intializing graphics subsystem...", L"", MB_OK);
  30.         d3dInterface = Direct3DCreate9(D3D_SDK_VERSION);
  31.         ZeroMemory(&framePresentationParameters, sizeof(framePresentationParameters));
  32.         // configure initial presentation parameters in here
  33.         if(bool(settings->GetVar("r_windowed")))
  34.         {
  35.             framePresentationParameters.Windowed = true;
  36.         }
  37.         else
  38.         {
  39.             framePresentationParameters.Windowed = false;
  40.         }
  41.         framePresentationParameters.BackBufferWidth = int(settings->GetVar("r_backBufferWidth"));
  42.         framePresentationParameters.BackBufferHeight = int(settings->GetVar("r_backBufferHeight"));
  43.         if(bool(settings->GetVar("r_useTripleBuffering")))
  44.         {
  45.             framePresentationParameters.BackBufferCount = 2;
  46.         }
  47.         else
  48.         {
  49.             framePresentationParameters.BackBufferCount = 1;
  50.         }
  51.         framePresentationParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
  52.  
  53.         framePresentationParameters.hDeviceWindow = targetWindow;
  54.         // end presentation params
  55.  
  56.         d3dInterface->CreateDevice(D3DADAPTER_DEFAULT, 
  57.                                     D3DDEVTYPE_HAL, 
  58.                                     targetWindow, 
  59.                                     D3DCREATE_HARDWARE_VERTEXPROCESSING, 
  60.                                     &framePresentationParameters, 
  61.                                     &d3dDeviceInterface);
  62.         return true;
  63.     }
  64.  
  65.     void ShutdownGraphicsSubsystem()
  66.     {
  67.         d3dInterface->Release();
  68.         d3dDeviceInterface->Release();
  69.     }
  70. protected:
  71.  
  72. private:
  73.     LPDIRECT3D9 d3dInterface;
  74.     LPDIRECT3DDEVICE9 d3dDeviceInterface;
  75.     D3DPRESENT_PARAMETERS framePresentationParameters;
  76.     HWND windowHandle;
  77. };
  78.  


Base CRenderer class definition:
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3. #include "CommonDefs.h"
  4. #include "MemoryPooledObject.h"
  5. #include "EngineSettingsManager.h"
  6. #include "Camera.h"
  7. #include <string>
  8. #include "Mathematics/Vectors.h"
  9.  
  10. using std::string;
  11.  
  12. #ifdef _WINDOWS
  13. // windows header, for hWnd definition
  14. #include <windows.h>
  15. #else
  16. // include whatever we need for Linux or OSX
  17. #endif
  18.  
  19.  
  20. class Renderer : public CMemoryPooledObject
  21. {
  22. public:
  23.  
  24.     virtual ~Renderer();
  25.  
  26.     virtual void DrawFrame()=0;
  27.  
  28. #ifdef _WINDOWS    // building for Windows, we need the HWND for the window
  29.     virtual bool InitializeGraphicsSubsystem(HWND &targetWindow, CEngineSettingsManager* settings)
  30.     {
  31.         MessageBox(NULL, L"Warning, base renderer class InitializeGraphicsSubsystem() called!", L"", MB_OK);
  32.         return false;
  33.     }
  34. #else
  35.     virtual bool InitializeGraphicsSubsystem();
  36.     {
  37.     }
  38. #endif    // _WINDOWS
  39.  
  40.     virtual void ShutdownGraphicsSubsystem()=0;
  41.  
  42.     static CCamera* currentView;
  43. protected:
  44. private:
  45. };
  46.  


Pipeline class:
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3. #ifdef _WINDOWS
  4. #include "RendererDX9.h"
  5. // #include "RendererDX10.h"
  6. #endif
  7. // #include "RendererOGL21.h"
  8. // #include "RendererOGL30.h"
  9.  
  10. #include "Task.h"
  11. #include "EngineSettingsManager.h"
  12. #include "Thread.h"
  13. #include "CommonDefs.h"
  14.  
  15.  
  16. class CRenderPipeline
  17. {
  18. public:
  19.     CRenderPipeline(CEngineSettingsManager* _settingsManager);
  20.     ~CRenderPipeline();
  21. #ifdef _WINDOWS
  22.     bool CreateAPIInterface(HWND hWnd);    // returns whether or not it succeeded
  23. #else
  24.     bool CreateAPIInterface();
  25. #endif
  26.     bool DestroyAPIInterface();
  27.  
  28. #ifdef _WINDOWS
  29.     bool ReCreateDevice(HWND hWnd);    // called when settings are changed
  30. #else
  31.     bool ReCreateDevice();
  32. #endif
  33.     bool InitializeOverlayInterface();
  34.  
  35.     void OnStart(void* passedInData);
  36.  
  37.     forceinline unsigned int OnHeartbeat()
  38.     {
  39.         renderInterface->DrawFrame();
  40.         return 0;
  41.     }
  42.  
  43. protected:
  44.  
  45. private:
  46.     Renderer* renderInterface;    // the "physical" system that communicates with the API
  47.     CEngineSettingsManager* settingsManager;    // we retrieve various parameters and settings here so we may as well keep the address permanently
  48.     CRenderPipeline(const CRenderPipeline &pipeline);    // copying this seems stupid, deny the ability to do so
  49. #ifdef _WINDOWS
  50.     HWND window;
  51. #else
  52. #endif
  53. };
  54.  
  55.  
There ya go. Let me know if I'm missing anything, and I'd be happy to fill you in.
Aug 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.