[PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter crash

All bugs related to the 3D engine
Kelebrindae
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 01, 2008 3:23 pm

[PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter crash

Post by Kelebrindae »

Hi,

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
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: [PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter cr

Post by LuCiFeR[SD] »

I reported this to fred a while ago. If you edit your code like this:

Code: Select all

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)
 
EndProcedure


;- Initialization
InitEngine3D()
InitSprite()
InitKeyboard()

initScreenAnd3D()


;- 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)
    CloseScreen()
    CloseWindow(0)
    ; Reopen
    initScreenAnd3D()
  
  EndIf
Until KeyboardPushed(#PB_Key_Escape)

  ; Render
  RenderWorld()
  FlipBuffers()
  
End
I get an IMA on OpenWindowedScreen() whenever you press space

(Edit: Added the camera stuff back into the example)
Last edited by LuCiFeR[SD] on Fri Jan 25, 2013 6:15 pm, edited 2 times in total.
Kelebrindae
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 01, 2008 3:23 pm

Re: [PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter cr

Post by Kelebrindae »

Hmm... Not the same problem, I think.

In your version, there's no camera: I don't see why you expect it to work at all (lucky it runs the first time without crashing). :?

My problem is that "CloseScreen" seems to wipe out some resources from memory (not only the sprites, as said in the doc), and as far as I know, only Particle Emitters cannot be reloaded (Materials can be reloaded with "GetScriptMaterial", etc.).
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: [PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter cr

Post by LuCiFeR[SD] »

even if you create the camera... it still IMA's when you swich screen. It makes no difference at all.

what I am trying to say is that I don't believe the problem is with the commands you think it is.

I believe there is a problem with the way PB is handling its screens when using ogre, be it fullscreen or windowedscreens
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: [PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter cr

Post by LuCiFeR[SD] »

and just to add to this..... your original code with OnError support added (enable in compiler options and disable the debugger)

PNG image of error

Code: Select all

Declare ErrorHandler()
Declare initScreenAnd3D()
OnErrorCall(@ErrorHandler())

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
Procedure ErrorHandler()
  
  ErrorMessage$ = "A program error was detected:" + Chr(13) 
  ErrorMessage$ + Chr(13)
  ErrorMessage$ + "Error Message:   " + ErrorMessage()      + Chr(13)
  ErrorMessage$ + "Error Code:      " + Str(ErrorCode())    + Chr(13)  
  ErrorMessage$ + "Code Address:    " + Str(ErrorAddress()) + Chr(13)
 
  If ErrorCode() = #PB_OnError_InvalidMemory   
    ErrorMessage$ + "Target Address:  " + Str(ErrorTargetAddress()) + Chr(13)
  EndIf
 
  If ErrorLine() = -1
    ErrorMessage$ + "Sourcecode line: Enable OnError lines support to get code line information." + Chr(13)
  Else
    ErrorMessage$ + "Sourcecode line: " + Str(ErrorLine()) + Chr(13)
    ErrorMessage$ + "Sourcecode file: " + GetFilePart(ErrorFile()) + Chr(13)
  EndIf
 
  ErrorMessage$ + Chr(13)
  ErrorMessage$ + "Register content:" + Chr(13)
 
  CompilerSelect #PB_Compiler_Processor 
    CompilerCase #PB_Processor_x86
      ErrorMessage$ + "EAX = " + Str(ErrorRegister(#PB_OnError_EAX)) + Chr(13)
      ErrorMessage$ + "EBX = " + Str(ErrorRegister(#PB_OnError_EBX)) + Chr(13)
      ErrorMessage$ + "ECX = " + Str(ErrorRegister(#PB_OnError_ECX)) + Chr(13)
      ErrorMessage$ + "EDX = " + Str(ErrorRegister(#PB_OnError_EDX)) + Chr(13)
      ErrorMessage$ + "EBP = " + Str(ErrorRegister(#PB_OnError_EBP)) + Chr(13)
      ErrorMessage$ + "ESI = " + Str(ErrorRegister(#PB_OnError_ESI)) + Chr(13)
      ErrorMessage$ + "EDI = " + Str(ErrorRegister(#PB_OnError_EDI)) + Chr(13)
      ErrorMessage$ + "ESP = " + Str(ErrorRegister(#PB_OnError_ESP)) + Chr(13)
 
    CompilerCase #PB_Processor_x64
      ErrorMessage$ + "RAX = " + Str(ErrorRegister(#PB_OnError_RAX)) + Chr(13)
      ErrorMessage$ + "RBX = " + Str(ErrorRegister(#PB_OnError_RBX)) + Chr(13)
      ErrorMessage$ + "RCX = " + Str(ErrorRegister(#PB_OnError_RCX)) + Chr(13)
      ErrorMessage$ + "RDX = " + Str(ErrorRegister(#PB_OnError_RDX)) + Chr(13)
      ErrorMessage$ + "RBP = " + Str(ErrorRegister(#PB_OnError_RBP)) + Chr(13)
      ErrorMessage$ + "RSI = " + Str(ErrorRegister(#PB_OnError_RSI)) + Chr(13)
      ErrorMessage$ + "RDI = " + Str(ErrorRegister(#PB_OnError_RDI)) + Chr(13)
      ErrorMessage$ + "RSP = " + Str(ErrorRegister(#PB_OnError_RSP)) + Chr(13)
      ErrorMessage$ + "Display of registers R8-R15 skipped."         + Chr(13)
 
    CompilerCase #PB_Processor_PowerPC
      ErrorMessage$ + "r0 = " + Str(ErrorRegister(#PB_OnError_r0)) + Chr(13)
      ErrorMessage$ + "r1 = " + Str(ErrorRegister(#PB_OnError_r1)) + Chr(13)
      ErrorMessage$ + "r2 = " + Str(ErrorRegister(#PB_OnError_r2)) + Chr(13)
      ErrorMessage$ + "r3 = " + Str(ErrorRegister(#PB_OnError_r3)) + Chr(13)
      ErrorMessage$ + "r4 = " + Str(ErrorRegister(#PB_OnError_r4)) + Chr(13)
      ErrorMessage$ + "r5 = " + Str(ErrorRegister(#PB_OnError_r5)) + Chr(13)
      ErrorMessage$ + "r6 = " + Str(ErrorRegister(#PB_OnError_r6)) + Chr(13)
      ErrorMessage$ + "r7 = " + Str(ErrorRegister(#PB_OnError_r7)) + Chr(13)
      ErrorMessage$ + "Display of registers r8-R31 skipped."       + Chr(13)
 
  CompilerEndSelect
 
  MessageRequester("Guru Meditation"+ Str(ErrorCode())+"."+Str(ErrorAddress()), ErrorMessage$)
  End
 
EndProcedure
Kelebrindae
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 01, 2008 3:23 pm

Re: [PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter cr

Post by Kelebrindae »

Ok, I see what you mean.

(Also: "Guru meditation", heh? It brings back good memories...)
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: [PB5.10b5 x86] CloseScreen = GetScriptParticleEmitter cr

Post by LuCiFeR[SD] »

Kelebrindae wrote:Ok, I see what you mean.

(Also: "Guru meditation", heh? It brings back good memories...)
Kelebrindae,I am happy that we finally understand each other :).

As for the "Guru Meditation" thing hehe, I have very good memories of those days too :). And Ironically if this bug didn't exist, you would have been even more amused by the way I display it normally LOL
Post Reply