473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Fun with constructors, inheritance

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
2 1732
weaknessforcats
9,208 Expert Mod 8TB
Show me the code from the function arguments to where the instantiation should occur.
Aug 12 '07 #2
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

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

Similar topics

4
by: Jimmy Johns | last post by:
Hi, I have some classes as follows: #include <iostream> using namespace std; class A { public: virtual A* clone() const = 0; };
7
by: Beach Potato | last post by:
I guess I've been out of C++ for a while, since right now I don't seem to get a simple solution for overriding inherited constrictors. What worked in Borland C++ & Pascal (and Java, if I remember...
5
by: Jochen Zeischka | last post by:
Hello, I just tried something with multiple inheritance and I have a problem with the construction of my object. There's a base class Base, containing an integer. The base class has 2 derived...
6
by: Doug | last post by:
I have a public abstract class that I want to inherit from in two other classes. My public abstract one has a constructor with several parameters. For some reason I cannot get to that constructor...
1
by: Russ Ford | last post by:
Hi all, I'm trying to get inheritance and constructors clear in my head (and in my code). I have the following inheritance situation (all derivations public): A is the base class B is...
3
by: hazz | last post by:
The following classes follow from the base class ' A ' down to the derived class ' D ' at the bottom of the inheritance chain. I am calling the class at the bottom, "public class D" from a client...
10
by: Kevin Buchan | last post by:
I searched the news group and could not find an answer to this question, so I'll go ahead and post it. Let's say I have a class A with a couple different constructors... nothin' special. Now,...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
7
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
6
by: Peng Yu | last post by:
Hi, I want B has all the constructors that A has. Obviously, the code below would not work. I could define a corresponding B's constructor for each A's constructor. But if A has many...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.