getting rid of onLostDevice and onResetDevice

Started by
7 comments, last by Evil Steve 16 years, 3 months ago
is there anyway to get rid of having to call onLostDevice and onResetDevice on most directx objects? would it be possible to create a wrapper for all objects and then store these in a (global?) list and execute them all at once? thus only having to write onLostDevice and onResetDevice only once in the main class/file... [Edited by - Dragon_Strike on January 2, 2008 5:12:26 PM]
Advertisement
My guess is you're using the Direct3D X (D3DX) portion of the Direct3D library. To my knowledge there is no way, however you could just have them call a globally defined function which would take (as a parameter) the pointer to your object with which you must restore, and then use that as the handle. In which case you won't have to write multiple functions.

In addition, you should be able to just pass the pointer of a function to handle it all to the structure for onLostDevice or onResetDevice. However, I don't use Direct3D X much (Only for setting up the perspective matrix and applying transormations and the such for matrices).


Cheers,

-naota
Madness never stops..... It takes a breather every once in a while, but then it grabs it's inhaler and chases you down the street with a cane.
Well, what I do is I have wrappers for OnLostDevice and OnReleaseDevice for each class in my engine that needs them (texture class, map class, map entity class, gui widget class, game class and engine class).

The engine contains a list of textures and a list of maps, and a list of top-level gui widgets as well as pointer to game. Map contains a list of map entities. So I just call engine's OnLostDevice, which calls game's OnLostDevice, then map's OnLostDevice, then loops through all top-level GUI widgets and calls OnLostDevice for those. Map's OnLostDevice calls OnLostDevice for every map entity. That's it, now every object has got OnLostDevice called, and same with OnResetDevice.
i was thinking about having some kind of global list like

using std::vector;
using boost::intrusive_ptr;
using boost::any;

vector<intrusive_ptr<any>> D3DXObjectList;

the problem becomes however how the program can decide if the object has a onLostDevice/onResetDevice function and if it has it should call it...

something like...

BOOST_FOREACH(intrusive_ptr<any> Object, D3DXObjectList)
{
/*....
if (Object has onLostDevice)
Object->OnLostDevice();
....*/

}

are all D3DX object derived from some baseclass i can use here?

[Edited by - Dragon_Strike on January 3, 2008 2:20:29 AM]
typedef void (__stdcall *pFuncVV) (void);class cClass{    // blah blah blah    pFuncVV onLostDeviceF;    pFuncVV onResetDeviceF;    // constructor/destructors and other functions here    void onLostDevice(void);    void onResetDevice(void);};void cClass::onLostDevice(void){    if (onLostDeviceF != NULL)    {        onLostDeviceF();    }}void cClass::onResetDevice(void){    if (onResetDeviceF != NULL)    {        onResetDeviceF();    }}


Generally you could do something like that, if I'm understanding you correctly.


Cheers,

-naota
Madness never stops..... It takes a breather every once in a while, but then it grabs it's inhaler and chases you down the street with a cane.
Quote:Original post by ValMan
Well, what I do is I have wrappers for OnLostDevice and OnReleaseDevice for each class in my engine that needs them (texture class, map class, map entity class, gui widget class, game class and engine class).

The engine contains a list of textures and a list of maps, and a list of top-level gui widgets as well as pointer to game. Map contains a list of map entities. So I just call engine's OnLostDevice, which calls game's OnLostDevice, then map's OnLostDevice, then loops through all top-level GUI widgets and calls OnLostDevice for those. Map's OnLostDevice calls OnLostDevice for every map entity. That's it, now every object has got OnLostDevice called, and same with OnResetDevice.
I have something similar to this. I have a ResettableObject class, which all objects that need a OnLostDevice() or OnResetDevice() handler derive from.
The ResettableObject class has two pure virtual functions, for OnLostDevice() and OnResetDevice(), and it [un]registers itself with the graphics system in the constructor/destructor. That way there's only one type to iterate through on lost / reset device, and gives the advantage that the graphics system can be in control of resetting the device and notifying the appropriate objects.
One solution is to move to Direct3D10. Direct3D10 has no lost devices, since the runtime automatically handles that for you (possible due to virtualisation changes in Windows Vista, from what I hear).
NextWar: The Quest for Earth available now for Windows Phone 7.
device lost, my nightmare. I have struggle with it for half year, and now I don't really solve it. there are so many reasons can make a device lost, not releasing your resource is only one reason. A video driver bug can also make a device lost, and can't be restored. This happens on both Nvidia card and Ati agp card. Now it seems I met a more interesting device lost case, it like this:
1)first, the device lost because a Ctrl+alt+del
2)after the user unlock the pc, I begin to restore the device
3)before I finish restoring the device(Maybe the computer is very busy, so the restoring operation take a long time), the user lock computer again, and this make a second device lost
4)the game crash.
The above situation is just my guess from the crash log file. I never can reproduce this crash on my computer. And even the crash is just like my guess, I don't know how to solve it, if I solve the second device lost, how about the third one? I am gonna be crazy.
Quote:Original post by codefuns
device lost, my nightmare. I have struggle with it for half year, and now I don't really solve it. there are so many reasons can make a device lost, not releasing your resource is only one reason. A video driver bug can also make a device lost, and can't be restored. This happens on both Nvidia card and Ati agp card. Now it seems I met a more interesting device lost case, it like this:
1)first, the device lost because a Ctrl+alt+del
2)after the user unlock the pc, I begin to restore the device
3)before I finish restoring the device(Maybe the computer is very busy, so the restoring operation take a long time), the user lock computer again, and this make a second device lost
4)the game crash.
The above situation is just my guess from the crash log file. I never can reproduce this crash on my computer. And even the crash is just like my guess, I don't know how to solve it, if I solve the second device lost, how about the third one? I am gonna be crazy.
Your code should be something like this:
Assumes there's a member bool m_bDeviceLostRender(){   // Check if it's ok to render...   result = TestCooperativeLevel()   if result = D3DERR_DEVICELOST      if m_bDeviceLost = false         m_bDeviceLost = true         Call OnLostDevice() for any objects needed      endif      return;   elseif result = D3DERR_DEVICENOTRESET      Attempt to reset the device then call OnResetDevice() for everything      If device reset fails with D3DERR_DEVICELOST, just silently fail, don't error out      if reset succeeded         m_bDeviceLost = false;      endif   elseif result = D3DERR_DRIVERINTERNALERROR      Exit application, fatal internal error   endif   // Do any rendering here   // Present   result = Present()   if FAILED(result) && result != D3DERR_DEVICELOST      Error in present, either ignore (And catch in TestCooperativeLevel() next tick) or do error handling here   endif}

That way if Reset() says the device is still lost, you do nothing and wait for the time to reset it.

This topic is closed to new replies.

Advertisement