Pressing key 1 twice still crashes the rendertexture. You just need to catch the error.
Code: Select all
tx = CreateRenderTexture(#PB_Any, CameraID(0), ScreenWidth(), ScreenHeight(), #PB_Texture_AutomaticUpdate, "Texture1")
Code: Select all
tx = CreateRenderTexture(#PB_Any, CameraID(0), ScreenWidth(), ScreenHeight(), #PB_Texture_AutomaticUpdate|#PB_Texture_CameraViewPort, "Texture1")
When using #PB_Texture_AutomaticUpdate, you must also use the #PB_Texture_CameraViewPort flag - otherwise you crash...
UpdateRenderTexture() must still be used with #PB_Texture_AutomaticUpdate.
Code: Select all
;Example works fine in PB 5.4X - but crashes with ima on 5.6X after a couple of saves.
;Switch between keys 1 and 2 or press 1 or 2 twice..The images are saved on each keypress-
;Just not on PB PB 5.6X (the second keypress results in a crash) - haven't tried PB 5.50 but I guess it's the same as 5.6X.
InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()
Structure _object
id.i
ma.i
ms.i
tx.i
EndStructure
Declare.s NewTexturename(Base.s)
Global o._object, tx.i, pa.s
pa = GetPathPart(ProgramFilename()) ; path to save rendered texture
OpenWindow(0, 0, 0, 800, 600, "Crash - ima", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
CreateCamera(0, 0, 0, 50, 100)
CreateCamera(1, 50, 0, 50, 100)
MoveCamera(0, -3, 0, 5)
MoveCamera(1, 3, 0, 5)
CameraLookAt(0, 0, 0, 0)
CameraLookAt(1, 0, 0, 0)
o\ms = CreateCube(#PB_Any, 1)
CompilerIf #PB_Compiler_Version < 550
o\tx = CreateTexture(#PB_Any, 64, 64)
CompilerElse
o\tx = CreateTexture(#PB_Any, 64, 64, "Cube")
CompilerEndIf
StartDrawing(TextureOutput(o\tx))
Box(0, 0, 64, 64, $00FFFF)
StopDrawing()
o\ma = CreateMaterial(#PB_Any, TextureID(o\tx))
o\id = CreateEntity(#PB_Any, MeshID(o\ms), MaterialID(o\ma), 0, 0, -2)
Repeat
Repeat
ev = WindowEvent()
Until ev = 0
ExamineKeyboard()
If KeyboardReleased(#PB_Key_1) ;Auto update
tx = CreateRenderTexture(#PB_Any, CameraID(0), ScreenWidth(), ScreenHeight(), #PB_Texture_AutomaticUpdate, "Texture1")
;Won't work without UpdateRenderTexture() even though the manual states otherwise..(PB 4.4X and up) - not a big problem, the crash is.
UpdateRenderTexture(tx)
SaveRenderTexture(tx, pa + "Picture_1_cam1.jpg")
ElseIf KeyboardReleased(#PB_Key_2) ; Manual update
tx = CreateRenderTexture(#PB_Any, CameraID(1), ScreenWidth(), ScreenHeight(), #PB_Texture_ManualUpdate, "Texture2")
UpdateRenderTexture(tx)
SaveRenderTexture(tx, pa + "Picture_2_Cam2.jpg")
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)