Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Microsoft Windows

SDK: losing directdraw on shiva shutdown

Windows DX9/OpenGL 2 Standalone Apps

SDK: losing directdraw on shiva shutdown

Postby cchaos_jond » 02 Feb 2010, 19:31

I'm trying to run shiva in a program that's already setup with directdraw in fullscreen mode. The program has to switch back and forth between shiva and the main program. In fullscreen mode, shutting down shiva will make the main program appear to lose the surfaces or something. Attempts to restore the surfaces or reset the device doesn't seem to work, but hitting the button to load shiva again will allow shiva to draw again (but shutting down again doesn't let the main program work, and so on). Alt+tabbing after a shutdown will restore the main program's drawing capabilities, but manually doing (in a sense, faking) the alt+tab restore logic doesn't seem to do anything since the surfaces are not truly lost.

Any thoughts on this problem?

The only solution I've found so far has been to let s3d be set to fullscreen if the main program is fullscreen. Then when shiva s3d shuts down, the screen resolution is reset, so then I set the display mode right after that. Meaning 2 screen resolution changes back-to-back, which creates a little flicker. That flicker may or not be acceptable, so I'm wondering if anyone has any other suggestions. Maybe there's an s3d option to not take over and release the dx stuff? Use what's already available? I don't know.
cchaos_jond
Junior Boarder
Junior Boarder
 
Posts: 23
Location: Dallas

Re:SDK: losing directdraw on shiva shutdown

Postby NiCoX » 02 Feb 2010, 21:47

Hi jond,

If I understand well, you want the main program to run in fullscreen, and the ShiVa application to run in windowed, isn't it ? Or do the ShiVa program also have to be fullscreen ? (I think I'm a little confused by your last paragraph :))
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re:SDK: losing directdraw on shiva shutdown

Postby cchaos_jond » 03 Feb 2010, 00:15

They would both run in fullscreen, but they're also both the same exe. Game exe loads in fullscreen, button is pressed, shiva is loaded in fullscreen through game exe, exit button in shiva returns to normal state of game exe still in fullscreen.

The shiva package is just loaded right there inside of the normal game exe, as sort of a tacked on part of the normal game. Ideally, it would all appear seamless.

For example, the normal game state is not done with shiva and is a 2D directdraw program. A button can be pressed for a little bonus part of the normal game, adding this separate-but-still-connected 3D segment of the game. Then the user can return back to the normal 2D part (shutting down s3d).

Sorry for any confusion.
cchaos_jond
Junior Boarder
Junior Boarder
 
Posts: 23
Location: Dallas

Re:SDK: losing directdraw on shiva shutdown

Postby NiCoX » 03 Feb 2010, 15:46

Hi,

Have you tested to launch the S3DEngine in windowed, but maximized, and perhaps child of your window (or another window created by you) ?

Functions to tweak :
S3DClient_SetFullscreen --> put false
S3DClient_SetGraphicContainer --> try providing a parent window

The trick (I think) is to avoid the engine to be launched in *true* fullscreen, avoiding the "ChangeDisplaySettings" function to be called (this is the one that causes a device lost on D3D).
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re:SDK: losing directdraw on shiva shutdown

Postby cchaos_jond » 03 Feb 2010, 17:04

Unfortunately, we were setting the s3d fullscreen option to false and it was still being lost. Then I tried making s3d use a separate window but that also had no luck. Very strange, I think.

When those didn't work and some reset/restore attempts didn't work either, I just went with the method of setting fullscreen to true and changing the display mode on s3d shutdown. But like I said, that may not be acceptable (haven't heard back yet on whether that fix is okay).

Perhaps there was something else going on with the separate window method when I tried it, so I may give that another shot if I have to find a different solution than the display mode one.
cchaos_jond
Junior Boarder
Junior Boarder
 
Posts: 23
Location: Dallas

Re: SDK: losing directdraw on shiva shutdown

Postby cchaos_colin » 02 Nov 2010, 18:27

Updating this thread with some more information, since this bug is starting to block progress...

I've tried creating a separate window for ShiVa to run in, using a fake-fullscreen setup of creating the window with the TOPMOST flag. On my mutlimonitor setup, I'm seeing flashes on the other screen as if ShiVa is resizing the desktop, even if it is already set to the desired resolution. Shutting down ShiVa, followed by destroying the window, results in a DEVICE_NOTRESET error on my next flip, and calling the device->Reset() at this point or right after the ShiVa shutdown gives an invalid_call error.

If I don't call any S3DClient_RunOneFrame() functions, I can set everything up about ShiVa, shut it down, and resume normal functioning of the containing program.

The interesting thing is, this only seems to happen if I'm running my primary monitor in the desired fake-fullscreen resolution (in this case, 1024x768). If I run at a higher res, of course the windows only draw to the upper left corner of the screen, but I can come and go from ShiVa as desired. If I have the program resize the display, then I always end up with a DEVICE_NOTRESET after ShiVa shuts down.

My setup calls are:

S3DClient_LoadDLL( );
CreateShiVaWindow(); // Creates fake fullscreen, topmost window called gShiVaHWnd
S3DClient_Init( "./" );
S3DClient_SetFullscreen( false );
S3DClient_SetClientType( S3DClient_Type_Embedded );
S3DClient_SetGraphicContainer( gShiVaHWnd, 0, 0, DisplayWidth, DisplayHeight );
S3DClient_SetInputContainer( gShiVaHWnd, 0, 0, DisplayWidth, DisplayHeight );

And to shut down:
S3DClient_Shutdown( ) ;
S3DClient_FreeDLL( ) ;
DestroyShiVaWindow( );

Do you have any ideas on this? I've been trying everything I can think of, but I'm running into a wall...
cchaos_colin
Senior Boarder
Senior Boarder
 
Posts: 41

Re: SDK: losing directdraw on shiva shutdown

Postby NiCoX » 02 Nov 2010, 18:52

Hi,

And if you just hide the 3D window instead of destroying it, is the DirectDraw context is also lost?

Code: Select all
::ShowWindow ( gShiVaHWnd, SW_HIDE ) ;


And if you set the 3D window size to 1024x767 (instead of 1024x768), leaving one pixel band at the bottom of the screen (so forcing the driver to *not* consider it fullscreen), is the DirectDraw context is also lost?
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re: SDK: losing directdraw on shiva shutdown

Postby cchaos_colin » 02 Nov 2010, 19:01

Correct.. in fact, I just did a few more tests, and I will always get the device not reset the very next time I try a flip on the outer program, it doesn't matter if ShiVa has been destroyed or not, ShiVa's window destroyed or not, etc. All that matters is that the primary display resolution matches the rendering window for my outer program and ShiVa, it seems, and that ShiVa has run for a few frames at least.

I thought our movies might have something to do with it, but I removed them, and got the same results.
cchaos_colin
Senior Boarder
Senior Boarder
 
Posts: 41

Re: SDK: losing directdraw on shiva shutdown

Postby Yopia » 02 Nov 2010, 19:08

Hi,

You should take care about the window flag WS_EX_TOOLWINDOW and fullscreen mode.
Have a look about that : http://msdn.microsoft.com/en-us/library/ms893093.aspx

Maybe you will find a clue ^^
User avatar
Yopia
Platinum Boarder
Platinum Boarder
 
Posts: 630

Re: SDK: losing directdraw on shiva shutdown

Postby cchaos_colin » 02 Nov 2010, 19:25

Ah, right, we're using WS_EX_TOPMOST, not WS_EX_TOOLWINDOW, so I think we're good by this. Unless ShiVa is creating another window or something inside the DLL calls... but for my side of things, both windows I create look pretty much like the sample code you linked to.
cchaos_colin
Senior Boarder
Senior Boarder
 
Posts: 41

Re: SDK: losing directdraw on shiva shutdown

Postby NiCoX » 02 Nov 2010, 21:14

Could you test with the failsafe flag:

Code: Select all
S3DClient_LoadDLL( );
CreateShiVaWindow(); // Creates fake fullscreen, topmost window called gShiVaHWnd
S3DClient_Init( "./" );
S3DClient_SetFullscreen( false );
S3DClient_SetOption(S3DClientOptions_ForceFailsafe, 1 ); // <-------------------- THIS LINE
S3DClient_SetClientType( S3DClient_Type_Embedded );
S3DClient_SetGraphicContainer( gShiVaHWnd, 0, 0, DisplayWidth, DisplayHeight );
S3DClient_SetInputContainer( gShiVaHWnd, 0, 0, DisplayWidth, DisplayHeight );


This will force the engine to use DirectX rendering back-end, and in this mode we never call the Windows function ChangeDisplaySettings. It's to verify if the problem is caused by this function call.
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re: SDK: losing directdraw on shiva shutdown

Postby cchaos_colin » 02 Nov 2010, 21:19

That did the trick! No more flashes on my second monitor, and we gracefully go back to the main application now.
cchaos_colin
Senior Boarder
Senior Boarder
 
Posts: 41

Re: SDK: losing directdraw on shiva shutdown

Postby NiCoX » 02 Nov 2010, 21:44

Great! Ok so I'll try to modify our OpenGL back-end so it does not call ChangeDisplaySettings at shutdown time if not necessary and post a link to the new DLL. That said, if you do not need special rendering effects, suggest you to stick with the DirectX back-end.
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re: SDK: losing directdraw on shiva shutdown

Postby cchaos_colin » 02 Nov 2010, 21:49

This seems to work great for us, so please don't drop other stuff you're on to rush out a new DLL or anything. We're not doing anything that special in terms of rendering, so this option will cover us with this project.

Thanks for helping me through this!
cchaos_colin
Senior Boarder
Senior Boarder
 
Posts: 41


Return to Microsoft Windows

cron