Closing and reopening the screen (to change the screen resolution, for example) prevents particle emitters created with "GetScriptParticleEmitter" to initialize properly.
=> After closing + reopening then screen, "GetScriptParticleEmitter(...)" doesn't display anything, and "ParticleEmitterID(...)" crashes with "Specified #ParticleEmitter is not initialised".
Code: Select all
; Bug description:
;------------------
; Closing and reopening the screen (to change the screen resolution, for example)
; prevents particle emitters created with "GetScriptParticleEmitter" to initialize.
;
; NB: Run this source from PB's "Examples/3D" directory.
; Press [Space] to close/reopen the screen.
Global numParticleEmitter.i
; This proc opens a windowed screen, creates the camera and a particle emitter
Procedure initScreenAnd3D()
;- Window
OpenWindow(0, 0, 0, 800, 600, "CloseScreen causes particle emitters bug", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, 800,600, 0, 0, 0,#PB_Screen_SmartSynchronization)
;- Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,-100,200,#PB_Absolute)
CameraLookAt(0,0,-100,0)
RotateCamera(0,0,0,45)
;- Particle emitter
Parse3DScripts()
numParticleEmitter = GetScriptParticleEmitter(#PB_Any, "Examples/JetEngine1")
EndProcedure
;- Initialization
InitEngine3D()
InitSprite()
InitKeyboard()
Add3DArchive("Data/Textures" , #PB_3DArchive_FileSystem)
Add3DArchive("Data/Scripts" , #PB_3DArchive_FileSystem)
Add3DArchive("Data/Particles", #PB_3DArchive_FileSystem)
; Initialize screen and 3D elements
initScreenAnd3D()
Debug "First time: emitter ID = " + Str(ParticleEmitterID(numParticleEmitter))
;- Main loop
KeyboardMode(#PB_Keyboard_International)
Repeat
While WindowEvent() : Wend
ExamineKeyboard()
;- Press [Space] to close and reopen screen
If KeyboardReleased(#PB_Key_Space)
; Free all and close screen
FreeCamera(0)
FreeParticleEmitter(numParticleEmitter)
CloseScreen()
CloseWindow(0)
; Reopen
initScreenAnd3D()
Debug "After CloseScreen: emitter ID = " + Str(ParticleEmitterID(numParticleEmitter))
EndIf
; Render
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End