InitEngine3d() -> ReInitEngine3d() ?

Just starting out? Need help? Post your questions and find answers here.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

InitEngine3d() -> ReInitEngine3d() ?

Post by JonChaos »

hi
i would like to know if there is a way to re initialise the 3d engine
because as soon as a fullscreen 3d app is minimised and thereafter reactivated the app crashes

first i thougt there is a way to reload resources or such like the problem with reactivating fullscreen apps using sprites

but i havent foundt a solution/workaround for the problem with initengine3d()
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

you should make the program HALT if the window is not the active one.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

sorry but that hasnt worked

i tried with

Code: Select all

Repeat 
    WaitWindowEvent() 
Until IsScreenActive()<>0 
and some delay functions but the result is always the same
crash on return to the app
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

May be that works

Code: Select all

#hWnd = 0

InitSprite()

OpenWindow(#hWnd, 10, 10, 800, 600, #PB_Window_SystemMenu,  "Test")
OpenWindowedScreen(WindowID(), 200, 200, 400, 300, 0, 0, 0)

Repeat
  If IsScreenActive() And GetActiveWindow_() = WindowID(#hWnd)
    FlipBuffers()
    ClearScreen(0,0,0)
  EndIf
Until WindowEvent() = #PB_EventCloseWindow
cya dige
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Re: InitEngine3d() -> ReInitEngine3d() ?

Post by JonChaos »

thx but that is not the kind of solution im serchin for
because as soon as a fullscreen 3d app is minimised and thereafter reactivated the app crashes
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

i played a bit with ogre in c++ and i noticed the same behaviour

is there a workaround known or a fix in work ?

otherwise i have to switch back to c++ which means a lot more work than writin in pb
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

You should post your code here. Maybe there is something wrong.
I have coded with ogre a 3D city modell with more than 2Mio triangels,
livecam billboards, flood simulation etc...
And everything works fine.

Image

No problem to minimize and restore the screen/window ...

cya dige
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

even if u start it fullscreen
then hit alt-tab to switch to the desktop
and then restore the app

?
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

here is the code

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

#CameraSpeed = 5

  DefType.f KeyX, KeyY
  
  Add3DArchive("Data\"          , #PB_3DArchive_FileSystem)
 
  If OpenScreen(1024, 768, 16, "Test") <> 0

    AmbientColor(RGB(255,255,255))
    
    CreateMaterial  (0, LoadTexture(0, "Terrain_Texture.jpg"))
    AddMaterialLayer(0, LoadTexture(1, "Terrain_Detail.jpg"), 1)
    
    CreateTerrain("Terrain.png", MaterialID(0), 4, 0.6, 4, 4)

    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 128, 25, 128)
        
    Repeat
            
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
      
      EndIf
            
      Height.f = TerrainHeight(CameraX(0), CameraZ(0))
      
      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, -CameraY(0)+Height+8, KeyY)
            
      RenderWorld()
              
      If StartDrawing(ScreenOutput())
      FrontColor(255, 255, 255)
      DrawingMode(1)
      Locate(50, 50)  : DrawText(StrF(Engine3DFrameRate(0),1)+" FPS")
      Locate(50, 70) : DrawText(Str(CountRenderedTriangles())+" Triangles")
      StopDrawing()
      EndIf
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf    
End
i tried to pause the app while the window isnt active but that didnt solve the problem
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

First of all, I never really used OGRE but on the other hand it also
shouldn't be different than anything else because due to the nature
of multitasking enviornments like Windows, you should always check
whether your window receives messages or not.

I think you'll have to check if your application is 'active' at all.

Dige already suggested you to do it like this:

Code: Select all

If IsScreenActive() And GetActiveWindow_() = WindowID(#hWnd) 
[...]
Did you try that?
Good programmers don't comment their code. It was hard to write, should be hard to read.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

Did you try that?
yes i have
and i know that everybody else who tried to help hasnt cause pausing the main loop while the window isnt active doesnt change the behaviour of the program
but thx anyway
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Well, now I tried it myself...

Using IsScreenActive() helps to prevent the app from crashing
but I just didn't manage to get the app on focus again...

I searched this and the german forum seeing that quite a lot of people
reported this behaviour. (I even found another thread of yours ;))

Either we all don't understand the concept or there's a bug somewhere.
Seems like Fred has already been informed but didn't answer so far.

Using plain Direct3D (ie no OGRE) I'd do it like this:

Code: Select all

procedure IsDeviceActive()
  select d3dDevice\TestCooperativeLevel()
    case #D3DERR_DEVICELOST
      procedurereturn #FALSE
   
    case #D3DERR_DEVICENOTRESET
  
    if d3dDevice\Reset(@PresentParameters) <> #D3D_OK
      procedurereturn #FALSE
      
    else
      ; re-init scene here
      ; (ie. re-create all textures, vertex or index buffers
      ; initially created with #D3DPOOL_DEFAULT.
      ; We also lost the projection matrix and renderstates)
      
      ;
      
      ; done re-init
      procedurereturn #TRUE
    endif

    default
      procedurereturn #TRUE
  endselect
endprocedure
But AFAIK there's no PB-command that returns the necessary deviceinfo.


Fred? Can you shed light on this?
Good programmers don't comment their code. It was hard to write, should be hard to read.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

hmm
seems like this part of pb is not important enough to be discussed or fixed :(
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

bump
Post Reply