Problem with recreating a 3D screen

Everything related to 3D programming
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Problem with recreating a 3D screen

Post 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

User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Problem with recreating a 3D screen

Post by nco2k »

If OSVersion() = #PB_OS_Windows_ME : End : EndIf
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Re: Problem with recreating a 3D screen

Post 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.
Ziltch
User
User
Posts: 52
Joined: Sun Aug 03, 2003 12:05 am
Location: Australia

Re: Problem with recreating a 3D screen

Post 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
BinoX
User
User
Posts: 46
Joined: Mon Jan 31, 2005 11:57 am

Re: Problem with recreating a 3D screen

Post 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..
Post Reply