Entity Not Found
Blitz3D Forums/Blitz3D Programming/Entity Not Found
| ||
I am getting an "Entity Does Not Exist" MAV but I cannot see why. Admittedly, the setup here is a little complex, but essentially, after creating some sprites, if they are to be dynamically faded, the handle integers are passed into a Type which stores the relevant details on how to fade them The error occurs in the function shown here, where the actual Fading routine occurs. Function FadeEntities() ;Mode: 1 = Fade Out ;Mode: 2 = Fade In ;Mode: 3 = Pulsing ;Mode: 4 = Signal Flash Local nEntity% Local fAlpha# Local nDirection% Local nFadeMode Local fSpeed# Debug("FADE ENTITY","START") For IterLibrary.tFadeLibrary = Each tFadeLibrary nEntity%=IterLibrary\EntityReference% fAlpha#=IterLibrary\Alpha# nDirection%=IterLibrary\Direction% nFadeMode=IterLibrary\Mode% fSpeed#=IterLibrary\Speed# Debug("FADE ENTITY","PROCESSING ENTITY "+nEntity%) Debug("FADE ENTITY","CURRENT ALPHA: "+fAlpha#) Debug("FADE ENTITY","CURRENT DIRECTION: "+ nDirection%) Debug("FADE ENTITY","FADE MODE: "+ nFadeMode%) Debug("FADE ENTITY","FADE SPEED: "+ fSpeed#) Select nDirection% Case DIRECTION_NONE% Debug("FADE ENTITY","NO CHANGE TO FADING. REMOVING FROM LIBRARY") IterLibrary\EntityReference = 0 Delete IterLibrary Case DIRECTION_POSITIVE fAlpha=fAlpha+fSpeed# If fAlpha#>=1.0 fAlpha#=1.0 End If EntityAlpha nEntity%,fAlpha# IterLibrary\Alpha#=fAlpha# If fAlpha#=1.0 If nFadeMode%=GRAPH_FADE_MODE_FADE_IN% Debug("FADE ENTITY","ENTITY FADED IN. REMOVING FROM LIBRARY") IterLibrary\EntityReference = 0 Delete IterLibrary.tFadeLibrary End If If nFadeMode%<>GRAPH_FADE_MODE_FADE_IN% Debug("FADE ENTITY","ENTITY FULLY VISIBLE. DIRECTION CHANGING") IterLibrary\Direction%=DIRECTION_NEGATIVE% End If EndIf Debug("FADE ENTITY","NEW ALPHA: "+fAlpha#) Case DIRECTION_NEGATIVE fAlpha=fAlpha-fSpeed# If fAlpha#<=0.0 fAlpha#=0.0 End If EntityAlpha nEntity,fAlpha# IterLibrary\Alpha#=fAlpha# If fAlpha#=0.0 If nFadeMode%=GRAPH_FADE_MODE_FADE_OUT% Debug("FADE ENTITY","ENTITY FADED OUT. REMOVING FROM LIBRARY") IterLibrary\EntityReference = 0 ;DO NOT DESTROY ENTITY HANDLES, only the Library Reference. Faded Entities should be checked for Re-Displaying ;FreeEntity IterLibrary\EntityReference Delete IterLibrary.tFadeLibrary End If If nFadeMode%<>GRAPH_FADE_MODE_FADE_OUT% Debug("FADE ENTITY","ENTITY FULLY INVISIBLE. DIRECTION CHANGING") IterLibrary\Direction%=DIRECTION_POSITIVE% End If EndIf Debug("FADE ENTITY","NEW ALPHA: "+fAlpha#) End Select Next End Function nEntity$ ( equivalent to IterLibrary\EntityReference% ) is the cause of the MAV. According to Blitz Debugger, and my own Log files, nEntity and IterLibrary\EntityReference contain the same integer value as the actual Entity reference (declared elsewhere on loading as Global) I thought that maybe it could have been due to passing the value into the Type, or even where nEntity is termed as Local, however, I tried this small test to see if I could recreate the error, but this test works okay: Graphics3D 800,600,32,2 SetBuffer BackBuffer() Type Manipulate Field Entity% Field OtherField% End Type Global Sphere%=CreateSphere(50) Global DuplicateSphereHandle%=Sphere% StoreAsField(Sphere%) StoreAsField(DuplicateSphereHandle%) Test(Sphere%) Test(DuplicateSphereHandle%) For IterManipulate.Manipulate = Each Manipulate Local Ent=IterManipulate\Entity% Test(Ent%) Next Function Test(ManipulateHandle) EntityColor ManipulateHandle,255,0,0 End Function Function StoreAsField(HandleToStore) Store.Manipulate = New Manipulate Store\Entity%=HandleToStore Store\OtherField=MilliSecs() End Function Maybe I've missed something, such as a small typo or such. I have not used FreeEntity elsewhere, nor changed/duplicated the original reference. This is the only use of the Type, aside from the declaration and for its population which is: Function AddEntityFade(Entity%,Speed#,Mode%,InitialAlpha#) Debug("ADD ENTITY FADE","START") Debug("ADD ENTITY FADE","SETTING ENTITY "+Entity%+" TO FADE MODE "+Mode%+" WITH SPEED "+Speed#+" STARTING WITH ALPHA "+InitialAlpha#) NewFadeEntity.tFadeLibrary=New tFadeLibrary NewFadeEntity\EntityReference%=Entity% NewFadeEntity\Speed#=Speed# NewFadeEntity\Mode%=Mode% NewFadeEntity\Alpha#=InitialAlpha# If InitialAlpha#<1.0 NewFadeEntity\Direction%=DIRECTION_POSITIVE Else If InitialAlpha#>0.0 NewFadeEntity\Direction%=DIRECTION_NEGATIVE End If EndIf Debug("ADD ENTITY FADE","DONE. INITIAL DIRECTION: "+Direction%) End Function |
| ||
Just to note, the entities themselves DO exist, as I have performed operations on them (Using the reference passed to other functions) prior to the calling of this 'Fading' function. |
| ||
I find it a bit difficult testing this without being able to run it, but at some point you are removing the entity from the library by putting the handle to zero. Maybe you can see if, at the point where the error occurs, nEntity% = 0? |
| ||
I find it a bit difficult testing this without being able to run it, but at some point you are removing the entity from the library by putting the handle to zero. Maybe you can see if, at the point where the error occurs, nEntity% = 0? No, as I mentioned, The entity Handle is still a valid integer, both in the Type and the original handle. This can be verified by the logfile generated. Here's a section of the Debug log (created from the "Debug()" function) 13 May 2009 | 21:27:01 | LOADING TITLE | START 13 May 2009 | 21:27:01 | LOAD 2D IMAGE | LOADING F:\bb\Blitz\Space Invaders 2008\Video\System\TitleA.spr AS 32148584 13 May 2009 | 21:27:01 | LOAD 2D IMAGE | IMAGE LOADED. CALLING RESCALE 13 May 2009 | 21:27:08 | INITIALISING TITLE | START 13 May 2009 | 21:27:08 | ADD ENTITY FADE | START 13 May 2009 | 21:27:08 | ADD ENTITY FADE | SETTING ENTITY 32148584 TO FADE MODE 3 WITH SPEED 0.1 STARTING WITH ALPHA 1.0 13 May 2009 | 21:27:08 | ADD ENTITY FADE | DONE. INITIAL DIRECTION: 0 13 May 2009 | 21:27:08 | INITIALISING TITLE | TITLE INITIALISED 13 May 2009 | 21:27:11 | FADE ENTITY | START 13 May 2009 | 21:27:11 | FADE ENTITY | PROCESSING ENTITY 32148584 13 May 2009 | 21:27:11 | FADE ENTITY | CURRENT ALPHA: 1.0 13 May 2009 | 21:27:11 | FADE ENTITY | CURRENT DIRECTION: -1 13 May 2009 | 21:27:11 | FADE ENTITY | FADE MODE: 3 13 May 2009 | 21:27:11 | FADE ENTITY | FADE SPEED: 0.1 As you can see, the entity in question (32148584) is Loaded okay and the values match. If you wish to test the program in its current state, (to separate it all out would be a mammoth task and likely introduce more problems) I have uploaded the source here: http:\\homepage.ntlworld.com\teutanis_support\EKD\Space.zip |
| ||
Were you able to run it, Warner? If so, please let me know the results of any testing you have done. The "FadeEnties()" function is found within "\Lib\Graphics.bb" Thanks. |
| ||
I tried yesterday, but it was a bit of a headache to find it out. Today I looked again, and now I think I understand. It seems you are passing 2D images as FadeEntities. However, a 2D image is not an entity. That is why you can't use any of the Entity commands on it. It happens in LoadTitle() and InitializeTitle(). Instead of loading 2D images, you could maybe use sprites instead? |
| ||
Doh! Yes... you got it, thanks so much. I feel so dumb! |