Page 1 of 1

Once again, Ogre Related Crashing

Posted: Sun Dec 19, 2004 1:19 am
by Dreglor
it's isn't easy to find the cause of this stuff and im not very expericened using orge so it makes it diffucalt to find this out on my own.

so, i have code that will load a map thats almost complete it not finshed but i working out the bugs as i go. i've hit a snag, when creating the materials for the terrian of the map it seams to crash when trying to return from the procedure becasue of it cannot add the materail layer.

heres a stripped down version of my map editor (it alot bigger than this is belive me)

Code: Select all

;World Editor Test
;version 1.0.0.0
;date: 12-18-04
;by Dreglor

#SkyDomeCurve.f=30
#FogDensity.w=255
#FogStart.w=100
#FogEnd.w=200
#Cam_Near.w=10
#Cam_Far.w=200
#Window_WorldEditor=0

Procedure.b LoadMap(File.s)
  If FileSize(File)<=0
    ProcedureReturn 0
  EndIf
  If OpenFile(0,File)=0
    ProcedureReturn -1
  EndIf
  HML.l=ReadLong()
  BML.l=ReadLong()
  DML.l=ReadLong()
  SML.l=ReadLong()
  HMB=AllocateMemory(HML)
  If HMB=0
    CloseFile(0)
    ProcedureReturn-2
  EndIf
  ReadData(HMB,HML)
  DeleteFile("HeightTemp.tga")
  If OpenFile(1,"HeightTemp.tga")=0
    CloseFile(0)
    ProcedureReturn -3
  EndIf
  WriteData(HMB,HML)
  CloseFile(1)
  UseFile(0)
  FreeMemory(HMB)
  BMB=AllocateMemory(BML)
  If BMB=0
    CloseFile(0)
    ProcedureReturn -4
  EndIf
  ReadData(BMB,BML)
  If CatchImage(0,BMB)=0
    FreeMemory(BMB)
    CloseFile(0)
    ProcedureReturn -5
  EndIf
  FreeMemory(BMB)
  If CreateTexture(0,ImageWidth(),ImageHeight())=0
    FreeImage(0)
    CloseFile(0)
    ProcedureReturn -6
  EndIf
  StartDrawing(TextureOutput(0))
  DrawImage(ImageID(),0,0)
  StopDrawing()
  FreeImage(0)
  DMB=AllocateMemory(DML)
  If DMB=0
    CloseFile(0)
    ProcedureReturn -7
  EndIf
  ReadData(DMB,DML)
  If CatchImage(0,DMB)=0
    FreeMemory(DMB)
    CloseFile(0)
    ProcedureReturn -8
  EndIf
  FreeMemory(DMB)
  If CreateTexture(1,ImageWidth(),ImageHeight())=0
    FreeImage(0)
    CloseFile(0)
    ProcedureReturn -9
  EndIf
  StartDrawing(TextureOutput(1))
  DrawImage(ImageID(),0,0)
  StopDrawing()
  FreeImage(0)
  SMB=AllocateMemory(SML)
  If SMB=0
    CloseFile(0)
    ProcedureReturn -10
  EndIf
  ReadData(SMB,SML)
  DeleteFile("SkyTemp.tga")
  If OpenFile(1,"SkyTemp.tga")=0
    FreeMemory(SMB)
    CloseFile(0)
    ProcedureReturn -11
  EndIf
  WriteData(SMB,SML)
  CloseFile(1)
  FreeMemory(SMB)
  UseFile(0)
  X_Limit=ReadLong()
  Y_Limit=ReadLong()
  AmbientColor(ReadLong())
  If CreateMaterial(0,TextureID(0))=0
    ProcedureReturn -12
  EndIf
  If AddMaterialLayer(0,TextureID(1))=0
    FreeMaterial(0)
    ProcedureReturn -13 ;crashes here
  EndIf
  MaterialAmbientColor(0,ReadLong())
  MaterialDiffuseColor(0,ReadLong())
  MaterialSpecularColor(0,ReadLong())
  Fog(ReadLong(),#FogDensity,#FogStart,#FogEnd)
  Water_Level=ReadWord()
  Object_Count=ReadWord()
  CreateTerrain("HeightTemp.tga",MaterialID(0),10,2,10,1)
  SkyDome("SkyTemp.tga",#SkyDomeCurve)
  DeleteFile("HeightTemp.tga")
  DeleteFile("SkyTemp.tga")
  CloseFile(0)
  ProcedureReturn 1
EndProcedure

UseTGAImageDecoder()
If InitEngine3D()
  If InitSprite()
    OpenWindow(#Window_WorldEditor,0,0,800,600,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered,"World Editor")
    OpenWindowedScreen(WindowID(#Window_WorldEditor),140,10,660,490,0,0,0)
  Else
    MessageRequester("Fatal Error","DirectX7 Or Greater Direct Draw Libaries Could Not Be Loaded")
  EndIf
Else
    MessageRequester("Fatal Error","3D Engine Could Not Be Loaded")
EndIf
CreateCamera(0,0,0,100,100)
CameraRange(0,#Cam_Near,#Cam_Far)
Debug LoadMap("Startup.pwb")
if you require a test file use some images from the purebasic\example folder (renamed/converted of course) and this code
Please use tga format as thats the only decoder i have in use in the bugged code above

Code: Select all

;Create Startup file for World Editor
;12/16/04
;Dreglor
;
DeleteFile("Startup.pwb")
HFL.l=FileSize("Hieght.tga")
BFL.l=FileSize("Base.tga")
DFL.l=FileSize("Detail.tga")
SDL.l=FileSize("SkyDome.tga")
HFB.l=AllocateMemory(HFL)
BFB.l=AllocateMemory(BFL)
DFB.l=AllocateMemory(DFL)
SDB.l=AllocateMemory(SDL)
OpenFile(0,"Hieght.tga")
ReadData(HFB,HFL)
OpenFile(0,"Base.tga")
ReadData(BFB,BFL)
OpenFile(0,"Detail.tga")
ReadData(DFB,DFL)
OpenFile(0,"SkyDome.tga")
ReadData(SDB,SDL)
OpenFile(0,"Startup.pwb")
WriteLong(HFL)
WriteLong(BFL)
WriteLong(DFL)
WriteLong(SDL)
WriteData(HFB,HFL)
WriteData(BFB,BFL)
WriteData(DFB,DFL)
WriteData(SDB,SDL)
WriteFloat(128.0);X_Limit.f
WriteFloat(128.0);Y_Limit.f
WriteLong(RGB(128,128,128));World_Ambient_Color.l
WriteLong(RGB(255,255,255));Ambient_Color.l
WriteLong(RGB(255,255,255));Diffuse_Color.l
WriteLong(RGB(255,255,255));Specular_Color.l
WriteLong(RGB(128,128,128));Fog_Color.l
WriteWord(1);Water_Level.w ;use -1 for no water
WriteWord(-1);Object_Count.w ;use -1 for no objects
CloseFile(0)
Thanks in advance :)

Posted: Mon Dec 20, 2004 4:16 am
by Dreglor
hmm a found the problem i replaced the line

Code: Select all

If AddMaterialLayer(0,TextureID(1))=0 
with

Code: Select all

If AddMaterialLayer(0,TextureID(1),1)=0 
hard to miss a typo like that :o
but it now is just giving a black screen (yes i put in a render loop) proably meaning that the error not being displayed
i begining to be frustrated with pb version of orge :?

Posted: Tue Dec 21, 2004 6:01 am
by Amiga5k
I think you mean OGRE, rather than ORGE (sounds like orgy, which is an entirely different thing ;) )

Anyway, OGRE still has some maturing to do before it can be really considered for commercial apps\games. I think Fred has some major improvements coming for the 3D aspect of PureBasic, so stay tuned...

Russell

Posted: Tue Dec 21, 2004 6:15 am
by Dreglor
lol typos...
yeah i heard, i just hope it soon id like to a game some time next year
Edit:
I found why it all black but it not sure why it doing it...
the line: "CreateTerrain("HeightTemp.tga",MaterialID(0),10,2,10,1)"
seams to return 0
and found out that when the CreateTerrain() function works it returns a value thats greater than 0
now why is it returning 0 ....