Blitz3D+ Command Reference

TextureReloadError$ ( texture )

Parameters

texture - texture to ask about

Description

Returns why a texture's most recent reload failed, or an empty string.

When a reload goes wrong - a manual ReloadTexture or an automatic WatchTexture pickup - the game keeps showing the last-known-good pixels rather than breaking, which is exactly right but easy to miss: you saved the file, nothing changed on screen, and there is no crash to point at. TextureReloadError is where the answer lives. It returns the failure message for that texture's source, such as a file that no longer decodes with the original layout, or a texture that was never file-backed.

An empty string means there is nothing to report: the last reload succeeded, or none has been attempted. A successful reload clears any earlier message.

During live-editing sessions, print it near the thing you are tweaking - one Text call turns "why isn't my texture updating?" into an on-screen explanation. The same failures are also filed as error records in diagnostics (category "texture"), so DrawDiagnostics shows them too.

Requires Extended mode.

See also: ReloadTexture, WatchTexture, CountDiagnostics, DrawDiagnostics.

Example

; TextureReloadError Example
; --------------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

SeedRnd MilliSecs()

camera=CreateCamera()
PositionEntity camera,0,0,-4

light=CreateLight()
RotateEntity light,45,45,0

; Write the texture file this example will reload, then load it
PaintFile 30,70,160
crate=CreateCube()
texture=LoadTexture("reload_error_demo.bmp")
EntityTexture crate,texture

While Not KeyDown(1)

    ; Space repaints the file properly and reloads it - this succeeds
    If KeyHit(57) Then
        PaintFile Rand(0,255),Rand(0,255),Rand(0,255)
        ok=ReloadTexture(texture)
    EndIf

    ; B overwrites the file with junk and reloads - the reload fails,
    ; the crate keeps its previous pixels, and the error is recorded
    If KeyHit(48) Then
        file=WriteFile("reload_error_demo.bmp")
        WriteLine file,"this is not a bitmap"
        CloseFile file
        ok=ReloadTexture(texture)
    EndIf

    TurnEntity crate,0.5,1,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Space: good repaint   B: corrupt the file   Arrows: camera   Esc: exit"
    ; TextureReloadError holds the most recent failure, or "" after success
    If TextureReloadError(texture)<>"" Then Text 0,20,"TextureReloadError: "+TextureReloadError(texture) Else Text 0,20,"TextureReloadError is empty - last reload succeeded"

    Flip

Wend

; Remove the file this example created
FreeTexture texture
DeleteFile "reload_error_demo.bmp"

End

; Draw a coloured pattern and save it as the reloadable file on disk
Function PaintFile(red,green,blue)
    scratch=CreateTexture(64,64)
    SetBuffer TextureBuffer(scratch)
    ClsColor red,green,blue
    Cls
    Color 255-red,255-green,255-blue
    Oval 12,12,40,40,True
    SetBuffer BackBuffer()
    Color 255,255,255
    SaveBuffer TextureBuffer(scratch),"reload_error_demo.bmp"
    FreeTexture scratch
End Function

Index