Page 1 of 1

Problem with recreating a 3D screen

Posted: Tue Sep 26, 2017 5:59 pm
by mrw
Hi,
I´m trying to create a small program that can handle a 3D screen in different ways. One problem I have is that if I have an opened 3D screen, add the basic 3D stuff(light, mesh, camera) closes it, and then creates the same screen again, the program crashes. So I need help in figuring out(if possible) how to solve this.

The code below creates a 3D screen and displays a cube. If the users hits "F" I want it to close the screen and then create it again.
Or if the user hits "ALT+TAB" it closes the screen, creates a small window and waits for input. If the users then either TABs back to the program(to the small window) or clicks on it in the active programs list, the small window closes and then creates the screen.

The problem seems to be with the reinitialization of the basic 3D stuff. I have tried to free them up before I close the screen but that doesn´t help. My guess is that something else needs to be done for the new screen to be created properly. My fear is that this is an OGRE issue and can´t be solved. But I have faith in this forum :)

Can anyone solve this for me?

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

ExamineDesktops()

OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0),"3D Test",#PB_Screen_NoSynchronization, DesktopFrequency(0))

AmbientColor(RGB(80, 80, 100))
WorldShadows(#PB_Shadow_Additive)

mesh=CreateCube(#PB_Any,20)
CreateEntity(0, MeshID(mesh), #PB_Material_None)
RotateEntity(0,35,15,0)

light_Sun=CreateLight(#PB_Any, RGB(201, 226, 255), 0, 3000, 0)

cam_Main=CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(cam_Main,0,0,50)
CameraRange(cam_Main, 0, 5000)
CameraFOV(cam_Main, 90)
CameraBackColor(cam_Main, RGB(70, 100, 182))

Repeat       
  
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape) ;quit the program
    End
  ElseIf KeyboardReleased(#PB_Key_F)
    
    CloseScreen()
    OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0),"3D Test",#PB_Screen_NoSynchronization, DesktopFrequency(0))
    AmbientColor(RGB(80, 80, 100))
    WorldShadows(#PB_Shadow_Additive)

    mesh=CreateCube(#PB_Any,20)
    CreateEntity(0, MeshID(mesh), #PB_Material_None)
    RotateEntity(0,35,15,0)

    light_Sun=CreateLight(#PB_Any, RGB(201, 226, 255), 0, 3000, 0)

    cam_Main=CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(cam_Main,0,0,50)
    CameraRange(cam_Main, 0, 5000)
    CameraFOV(cam_Main, 90)
    CameraBackColor(cam_Main, RGB(70, 100, 182))
  EndIf
  
  If KeyboardPushed(#PB_Key_LeftAlt)
    If KeyboardPushed(#PB_Key_Tab)
      CloseScreen()
      OpenWindow(1,1,1,1,1, "3D Test" , #PB_Window_Minimize )
      Repeat
        Event= WaitWindowEvent(2)
      Until Event= #PB_Event_ActivateWindow 
      CloseWindow(1)
      
      OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0),"3D Test",#PB_Screen_NoSynchronization, DesktopFrequency(0))
      AmbientColor(RGB(80, 80, 100))
      WorldShadows(#PB_Shadow_Additive)

      mesh=CreateCube(#PB_Any,20)
      CreateEntity(0, MeshID(mesh), #PB_Material_None)
      RotateEntity(0,35,15,0)

      light_Sun=CreateLight(#PB_Any, RGB(201, 226, 255), 0, 3000, 0)

      cam_Main=CreateCamera(#PB_Any, 0, 0, 100, 100)
      MoveCamera(cam_Main,0,0,50)
      CameraRange(cam_Main, 0, 5000)
      CameraFOV(cam_Main, 90)
      CameraBackColor(cam_Main, RGB(70, 100, 182))
    EndIf    
  EndIf    
  
  RenderWorld()
  
  FlipBuffers()
  
ForEver


Re: Problem with recreating a 3D screen

Posted: Tue Sep 26, 2017 7:44 pm
by nco2k

Re: Problem with recreating a 3D screen

Posted: Wed Sep 27, 2017 11:10 am
by mrw
Ah, didnt´t find that post when I searched. Thanks!
But your code in the bugreport is easily worked around if you also close the window and then reopens that before the windowed screen.
Not the best solution ofc since you might not always want to close the window for several reasons. But a workaround nonetheless. And ofc the bug is still a bug.

But I can´t find any workaround when using OpenScreen().
Is there no way around this?

And more importantly why hasn´t this bug been fixed years ago?
Has there been some official statement regarding this? Is this the reason why ALT+TAB is disabled on fullscreens with 3D?
Is it a bug in the OGRE code or in the PB implementation?
If I were the PB developer I would definitely put this bug on the top of the "bugs to fix" list. I don´t think I have played any commercial game that crashes when doing an ALT+TAB so this really stands out. And in a very bad way.

Re: Problem with recreating a 3D screen

Posted: Thu Nov 09, 2017 8:59 am
by Ziltch
Fred has tried , but failed to fix this. It is a tricky prob in orge closing.
It has forced my video effects program to stay 2d only. :(
You get one 3d window/screen open per program launch. :(
It may never be fixed.

Mentioned in this thread.
http://www.purebasic.fr/english/viewtop ... =4&t=53166

Re: Problem with recreating a 3D screen

Posted: Thu Jan 25, 2018 11:05 am
by BinoX
Well, I know that I'm super late with a reply to this one....

But it works (mostly) fine if you use the OpenGL subsystem..