Strange behaviour/bug, need your help
Blitz3D Forums/Blitz3D Programming/Strange behaviour/bug, need your help
| ||
Hi everyone, I ran into a strange behaviour that drives me crazy. I've checked my code again and again the last 4 hours and I don't understand it. Could you do me a favour, run the code on your machine and see for yourself. It's part of my surface-manager I'm currently working on - i removed everything except the parts where my problem occurs. All this code does is creating some test-quads and storing them for later use. Everytime you press <Space> a quad will be created. And now the weird thing: The fourth quad makes the three previous disappear, the fifth makes them appear again. Same happens with 6th, 9th and 11th quad (didn't tested further). I cannot find any error in my code and this happens either with debugmode on or off. BUT if you uncomment the line with "debuglog" in the mainloop (and turn debugmode on), this bug will not show up. Here's the code: Type SM_Entity Field msh% Field srf% Field NewObj.SM_Object ; points to object we process Field NewObjVt% ; Stores Vertex-IDs for NewObj until SM_EndObject Field NewObjVtPtr% ; "Pointer" to last offset Field NewObjTris% ; stores Tri-IDs for NewObj until SM_EndObject Field NewObjTrisPtr% ; "Pointer" to last offset End Type Type SM_Object Field par.SM_Entity Field Tris% ; Int-Bank of tris belonging to this object End Type Function SM_CreateEntity%(parent%=0,entity_fx%=2) ;returns new entity Local sm.SM_Entity=New SM_Entity sm\msh=CreateMesh() sm\srf=CreateSurface(sm\msh) EntityFX (sm\msh,entity_fx) NameEntity (sm\msh,Handle(sm)) Return sm\msh End Function Function SM_BeginObject%(smid%,estimated_vt%=0,estimated_tri%=0) ;prepare a new object to add vertices/triangles ;RETURNS: handle of SM_Object Local sm.SM_Entity=Object.SM_Entity(EntityName(smid)) If sm=Null Then RuntimeError ("SM_BeginObject: Invalid SM_Entity") If sm\NewObj<>Null Then RuntimeError ("SM_BeginObject: Can't create two objects at once. Call SM_EndObject first") sm\NewObj=New SM_Object sm\NewObj\par=sm sm\NewObjTris=CreateBank (estimated_tri*4) : sm\NewObjTrisPtr=0 sm\NewObjVt=CreateBank (estimated_vt*4) : sm\NewObjVtPtr=0 Return Handle(sm\NewObj) End Function Function SM_EndObject%(smid%) ; finalize object-creation ;RETURNS: number of vertices added Local sm.SM_Entity=Object.SM_Entity(EntityName(smid)) If sm=Null Then RuntimeError ("SM_EndObject: Invalid SM_Object") If sm\NewObj=Null Then RuntimeError ("SM_EndObject: No SM_Object open") sm\NewObj\Tris=CreateBank(sm\NewObjTrisPtr) CopyBank(sm\NewObjTris,0,sm\NewObj\Tris,0,sm\NewObjTrisPtr) Local cnt%=sm\NewObjVtPtr/4 SMInt_UpdateNormals (sm\NewObj) FreeBank(sm\NewObjTris) : sm\NewObjTrisPtr=0 FreeBank(sm\NewObjVt) : sm\NewObjVtPtr=0 sm\NewObj=Null Return (cnt%) End Function Function SMInt_UpdateNormals (obj.SM_Object) ;maybe optimize this later and calculate just the new object If obj=Null Then RuntimeError ("SMInt_UpdateNormals: Invalid SM_Object - ERROR IN LIB, THIS SHOULD NOT HAPPEN") UpdateNormals (obj\par\msh) End Function Function SM_AddVertex% (smid%,x#=0,y#=0,z#=0,u#=0,v#=0) ;adds a vertex to current object ;RETURNS: Vertex-ID Local sm.SM_Entity=Object.SM_Entity(EntityName(smid)) If sm=Null Then RuntimeError ("SM_AddVertex: Invalid SM_Object") Local size%=BankSize(sm\NewObjVt) Local vt%=AddVertex(sm\srf,x,y,z,u,v) sm\NewObjVtPtr=sm\NewObjVtPtr+4 If sm\NewObjVtPtr > size Then ResizeBank(sm\NewObjVt,sm\NewObjVtPtr) PokeInt (sm\NewObjVt,sm\NewObjVtPtr-4,vt%) Return (vt%) End Function Function SM_AddTriangle% (smid%,v0%,v1%,v2%) ;adds a triangle to current object ;RETURNS: Triangle-ID Local sm.SM_Entity=Object.SM_Entity(EntityName(smid)) If sm=Null Then RuntimeError ("SM_AddTriangle: Invalid SM_Object") Local size%=BankSize(sm\NewObjTris) Local t%=AddTriangle(sm\srf,v0,v1,v2) sm\NewObjTrisPtr=sm\NewObjTrisPtr+4 If sm\NewObjTrisPtr > size Then ResizeBank(sm\NewObjTris,sm\NewObjTrisPtr) PokeInt (sm\NewObjTris,sm\NewObjTrisPtr-4,t) Return (t%) End Function ;================================================================ Graphics3D 1024,768,32,2 SetBuffer BackBuffer() cam=CreateCamera() PositionEntity cam,0,0,-20 AmbientLight(255,255,255) Local ent=SM_CreateEntity() Local v0,v1,v2,v3,px,py ; Hit <Space> to create a quad at random position. If you create the 4th quad, the previous three disappear. ; Create the 5th, and they appear again. The 6th makes all previous quads disappear again, then the 9th, the 11th => Stopped cheching While Not KeyDown(1) If KeyHit(57) SM_BeginObject (ent) px=Rnd(-8,8) : py=Rnd(-8,8) v0=SM_AddVertex (ent,px-1,py-1,0) v1=SM_AddVertex (ent,px-1,py+1,0) v2=SM_AddVertex (ent,px+1,py+1,0) v3=SM_AddVertex (ent,px+1,py-1,0) SM_AddTriangle (ent,v0,v1,v2) SM_AddTriangle (ent,v0,v2,v3) SM_EndObject (ent) ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ; !!!! Uncommenting this debuglog will prevent this strange behaviour - if you run in debugmode ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ; DebugLog "WHAT THE HELL!!!!" ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! EndIf RenderWorld Flip False Wend End Any hints or ideas to hunt this evil bug could save an old man's day... Sincerly Jake |
| ||
This code works.. no quads disapear on my machine. AMD Athalon XP2200+ 256mb ram NVIDIA GeForce4 Ti4200 AGP8X |
| ||
Hmm, really strange. On my machine (Athlon 1800, GForce6800 GT) this bug is reproducable, even after reboot. My driver is Detonator 6.14.10.6681 and I'm using dx9.0c and blitzcc v1.89 (I've read nothing good about 1.90, is this true?) Please could you post your driver/compiler-versions ? |
| ||
No problem here. Blitz 1.90 DX 9.0c |
| ||
in runs pretty fine on my machine, debug on and off, GForce 5200 ultra |
| ||
No prob here (tried dif colour depths windowed/full screen too without issue) Blitz1.90 W2000 Nvidia Quadro2 DX9.0b |
| ||
Wow, that code causes absolute havoc on my machine - completely crashing windows. :/ After several attempts, I managed to narrow the cause down to the Flip False! On my PC, at least, it seems this is the trouble because the buffers are getting flipped at VERY high speed because there's nothing to render, to begin with. My PC really doesn't like this. Changing to Flip True fixes it. My specs: Athlon 850Mhz, Win98SE, 128MB RAM, GeForce 256, DX8, Blitz3D 1.88 The good news is, nothing appears to be wrong with your code. The reason you think some quads aren't getting created is because they're being positioned exactly on top of other quads. Use EntityAlpha to make the quads semi transparent and you'll see them. The reason the same quads don't seem to appear every time you run is because you're not seeding the random number generator with SeedRnd MilliSecs(). |
| ||
I will check everything again later this day, trying Blitz v1.90, Flip True and maybe a newer gfx-driver. Thanks to all of you! @big10p They're really disappearing on my screen, this is not just about positioning. |
| ||
ok here, tried it on my old duron 800 w/gforce4mx |
| ||
..working fine here.. P4 2.8GHz, 4 Gigz RAM, NVidia A310 256 MB VRAM, WinXP Pro |
| ||
Finally, I figured it out. It's the problem big10p mentioned, when a loop is running too fast. a debuglog is very slow, "flip true" makes the whole loop slower, too. So when used in a game with Timing and a nice filled mainloop everything works well. Thanks again for all responses |