Loading problems

Previous topic - Next topic

MrTAToad

Every so often, on Windows machine, I find that some loading command just fails - either the program just stops or my loading system just goes into an infinite loop.  Run the program again and its all okay.

The other strange thing is that Moru's font system occasionally displays all text as fixed font - as no parameters change, I think, for some reason, a value passed to a function is either being corrupted or being mistaken for another...  Again, run the program again, and all is okay...

Ian Price

What are you loading - images/data/sounds?

I've never had a loading issue with any of the general commands - LOADBYTE, LOADWORD, LOADSPRITE, LOADANIM, LOADSOUND etc.

The only time I ever get infinite loops is if I accidentally forget to use SHOWSCREEN (and I've done this quite a few times - requires TaskManager to exit).

How big a problem is this? Does it happen often, infrequently? Any code/data examples?
I came. I saw. I played.

MrTAToad

It happens infrequently - but has been doing in previous versions (just never got around to mentioning it), and has a couple of times today.

I dont know whereabouts in my loading system it happens, but the code (if its any help) is :

Code (glbasic) Select
//! If the filename has a special code in it, then process it
FUNCTION checkForSpecialCode%:BYREF file$,loadType%
LOCAL temp$
LOCAL dirCode$="#"
LOCAL lanDirCode$="!"
LOCAL mediaPath$="Media/"

IF LEFT$(file$,LEN(lanDirCode$))=lanDirCode$
// ! code forces the file to be loaded from users selected language directory
file$=self.languagePath$+mediaPath$+self.loadDirList$[loadType%]+"/"+MID$(file$,LEN(lanDirCode$))
ELSE
// Anything else forces load from specificed directory
file$=mediaPath$+self.loadDirList$[loadType%]+"/"+file$
ENDIF
ENDFUNCTION

FUNCTION doLoadFiles$:usingShoeBox%,loadType%
LOCAL result$,file$
LOCAL l AS tLoadDataList
LOCAL bumpCode$="BUMP:"
LOCAL animCode$="ANIM:"
LOCAL rgbCode$="RGB:"
LOCAL width%,height%,loop%
LOCAL temp$[]

l.isBumpMap%=0
l.isAnim%=FALSE // Is an animated sprite
l.idNumber%=0
l.xSize%=0
l.ySize%=0
l.channel%=0 // Only used by the sound system
l.handleXOffset%=0
l.handleYOffset%=0
l.fileName$=""

SELECT loadType%
CASE self.LOAD_SOUND%
RESTORE soundsData

CASE self.LOAD_MUSIC%
RESTORE musicData

CASE self.LOAD_FIXEDFONT%
RESTORE fontsData

SETFONT FONT_DEFAULT%
GETFONTSIZE l.xSize%,l.ySize%
DIMPUSH self.fontLoadData[],l

CASE self.LOAD_PROFONT%
RESTORE ttFFontsData

CASE self.LOAD_3DOBJ
RESTORE graphics3DData

CASE self.LOAD_2DOBJ
RESTORE spritesData
ENDSELECT

result$=""

READ file$
WHILE file$<>"" AND result$=""
// Remove the extension if present
IF loadType%=self.LOAD_MUSIC%
FOR loop%=LEN(file$)-1 TO 0 STEP -1
IF MID$(file$,loop%,1)="."
file$=LEFT$(file$,loop%-1)
BREAK
ENDIF
NEXT

?IFDEF OSXUNI
?WARNING "Using OGG file"
INC file$,".ogg"

?ELSE
?WARNING "using MP3 file"
INC file$,".mp3"
ENDIF
?ENDIF

DEBUG "file:"+file$+"\n"
IF loadType%=self.LOAD_2DOBJ
l.isAnim%=FALSE

IF MID$(file$,0,LEN(rgbCode$))=rgbCode$
DIM temp$[0]
file$=MID$(file$,LEN(rgbCode$))
IF SPLITSTR(file$,temp$[],",")<>3
result$=self.invalidColourText$
ELSE
DEBUG "Colour : "+INTEGER(temp$[0])+" "+INTEGER(temp$[1])+" "+INTEGER(temp$[2])+"\n"
SETTRANSPARENCY RGB(INTEGER(temp$[0]),INTEGER(temp$[1]),INTEGER(temp$[2]))
READ file$
CONTINUE
ENDIF
ELSE
IF MID$(file$,0,LEN(bumpCode$))=bumpCode$
file$=MID$(file$,LEN(bumpCode$),LEN(file$))
l.isBumpMap%=TRUE
ELSE
l.isBumpMap%=FALSE
IF MID$(file$,0,LEN(animCode$))=animCode$
DIM temp$[0]
file$=MID$(file$,LEN(animCode$),LEN(file$))
IF SPLITSTR(file$,temp$[],",")<>3
result$=self.invalidAnimSpriteText$
ELSE
width%=INTEGER(temp$[0])
height%=INTEGER(temp$[1])
file$=temp$[2]
l.isAnim%=TRUE
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF

self.checkForSpecialCode(file$,loadType%)

IF (usingShoeBox%=FALSE AND DOESFILEEXIST(file$)=TRUE) OR (usingShoeBox%=TRUE)
SELECT loadType%
CASE self.LOAD_SOUND%
l.idNumber%=GENSOUND()
IF l.idNumber%<0
result$=self.allocateSoundIDErrorText$
ELSE
LOADSOUND file$,l.idNumber%,1
DIMPUSH self.soundLoadData[],l
ENDIF

CASE self.LOAD_MUSIC%
l.fileName$=file$
DIMPUSH self.musicLoadData[],l

CASE self.LOAD_FIXEDFONT%
l.idNumber%=GENFONT()
IF l.idNumber%<0
result$=self.allocateFontIDErrorText$
ELSE
LOADFONT file$,l.idNumber%
SETFONT l.idNumber%
GETFONTSIZE l.xSize%,l.ySize%
DIMPUSH self.fontLoadData[],l
ENDIF

CASE self.LOAD_PROFONT%
l.idNumber%=self.font.AddFont(file$,2)
IF l.idNumber%<0
result$=self.unableToLoadFileText$+file$
ELSE
DIMPUSH self.ttFontLoadData[],l
ENDIF

CASE self.LOAD_3DOBJ
l.idNumber%=GENX_OBJ()
IF l.idNumber%<0
result$=self.allocate3DObjectErrorText$
ELSE
X_LOADOBJ file$,l.idNumber%
DIMPUSH self.objectLoadData[],l
ENDIF

CASE self.LOAD_2DOBJ
IF result$=""
l.idNumber%=GENSPRITE()
IF l.idNumber%<0
result$=self.allocate2DObjectErrorText$
ELSE
IF l.isBumpMap%=TRUE
LOADBUMPTEXTURE file$,l.idNumber%
ELSE
IF l.isAnim%=TRUE
LOADANIM file$,l.idNumber%,width%,height%
l.xSize%=width%
l.ySize%=height%
ELSE
LOADSPRITE file$,l.idNumber%
GETSPRITESIZE l.idNumber%,l.xSize%,l.ySize%
ENDIF
ENDIF

// Set sprite handles
IF self.handleX%=HANDLE_LEFT%
l.handleXOffset%=0
ELSEIF self.handleX%=HANDLE_RIGHT%
l.handleXOffset%=l.xSize%
ELSE
l.handleXOffset%=l.xSize%/2
ENDIF

IF self.handleY%=HANDLE_TOP%
l.handleYOffset%=0
ELSEIF self.handleY%=HANDLE_BOTTOM%
l.handleYOffset%=l.ySize%
ELSE
l.handleYOffset%=l.ySize%/2
ENDIF

DIMPUSH self.spriteLoadData[],l
ENDIF
ENDIF
ENDSELECT

DDgui_WaitCursor(TRUE)
ELSE
result$=self.unableToFindFileErrorText$+file$
ENDIF

READ file$
WEND

SETTRANSPARENCY RGB(0,0,0)
RETURN result$
ENDFUNCTION

Ian Price

Woah! That's a lot of code. Does what you're doing really need to be that complex?
I came. I saw. I played.

MrTAToad

Its got a lot to do!