Data Realms Fan Forums http://45.55.195.193/ |
|
Yet Another Implementation Issue - now with added crashing http://45.55.195.193/viewtopic.php?f=73&t=17986 |
Page 1 of 2 |
Author: | PhantomAGN [ Mon Mar 01, 2010 6:44 pm ] |
Post subject: | Yet Another Implementation Issue - now with added crashing |
Howdy all. I've picked up work on a fairly simple scripted weapon again after a few months of "screw it, I have better things to do," and I'm having a hard time applying my concepts to script. The mod is similar to my previous Lua-based mortar, it is in fact a derivative. Thanks in advance for whatever advice/berating/corrections you can offer. Update, March 6th: http://pastebin.com/3i3knLcc I cannot for the life of me work out how to fix the random crashing. If anyone wants to get serious respect, they can guide me to the answer (or just hand it to me). If it's something obvious, feel free to call me an idiot. |
Author: | Grif [ Mon Mar 01, 2010 9:55 pm ] |
Post subject: | Re: Yet Another Implementation Issue |
to check that the gun is still held find the parent then check the presetname of any attachables with classname 'hdfirearm' to do your shenanigans with timers you can probably just set up some local circumstances with two timers total I'd suggest something like this: find parent, create one timer, do whatever initializing stuff required then do this function Update(self) if self.Age:IsPastSimMS(4000) == false then if self.firetimer:IsPastSimMS(200) == true then attachable check for gun goes here, though I really don't see it as being that necessary, if this is being run on the emitter then do this stuff: I'd suggest just finding the parent and doing getaimangle, it's probably the easiest way overall performs a pile of complex calculus using timer spawns particle with vector based on above math self.firetimer:Reset(); end end end the above method uses the internal age timer, with no additional overhead, to perform the lifetime based check, and therefore only uses up one timer. the timer organization goes from lowest cycle cost to highest, meaning it'd be more efficient, and should do what you need just fine. |
Author: | PhantomAGN [ Fri Mar 05, 2010 1:50 am ] |
Post subject: | Re: Yet Another Implementation Issue |
Ok, I implemented the timers and got something that runs. There's no checks for seeing if the gun is still held, that's on hold until it works again. The issue is, it will sometimes (almost half the time) simply crash CC, no OS errors, no noticeable CC console errors. It's not caused by the gun breaking, and the emitter can also delete itself fine. What should I be protecting against now? I've debugged it to a point at which I can no longer find the problem. Here's the code as of now. http://pastebin.com/Y3NPXy3L The targeting system seems broken, but I cannot fix it if I cannot test it without it crashing while firing. |
Author: | Grif [ Fri Mar 05, 2010 3:43 am ] |
Post subject: | Re: Yet Another Implementation Issue |
are you setting anything without checking if it exists first? that's the usual cause of instant-crash hangups with no console errors |
Author: | PhantomAGN [ Fri Mar 05, 2010 4:45 am ] |
Post subject: | Re: Yet Another Implementation Issue |
Hmm. I'll have to check that, I never considered something like that. |
Author: | Grif [ Fri Mar 05, 2010 6:08 am ] |
Post subject: | Re: Yet Another Implementation Issue |
it's because there aren't proper pointer death checks if you are, say, setting 'self.Pos' to 'self.target.Pos' and self.target is a pointer to an actor, when that actor dies, your script will forcequit CC. |
Author: | PhantomAGN [ Fri Mar 05, 2010 8:55 am ] |
Post subject: | Re: Yet Another Implementation Issue |
Well, in this case the crash happens whether or not anything is dying or destroyed, I must be referencing something that does not exist yet. Edit: Still not even sure why it's crashing. Updated to this: http://pastebin.com/3i3knLcc Fixed one issue, but it seems to crash whenever the emitter destroys itself. My targeting is still very broken too. Edit: Changed the OP to reflect current broken status. |
Author: | PhantomAGN [ Thu Mar 11, 2010 4:55 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
Bumping to see if anyone wants to basically take what I have and fix it. I no longer know what I'm doing, and the code "feels right," and I cannot determine what's wrong. I may be unable to see the forest for the trees. Same as above,http://pastebin.com/3i3knLcc, and I'm not sure how to make it work without crashing. If you think you can assist you can post here or PM/email me, and I'll hand you the mod proper if you need it. Thanks. |
Author: | ScifiSpirit [ Fri Mar 12, 2010 12:42 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
Well it seems to me like what Grif said still stands. Grif wrote: it's because there aren't proper pointer death checks You have to be careful with these references (or pointers if you want to call them that): Line 2: self.targetpaintergood = CreateAEmitter("Target Painter Good"); Line 9: self.beamparticle = CreateAEmitter("Particle Auto Mortar"); Line 25: self.parent = ToActor(actor); Line 26: self.parentgun = ToHDFirearm(gun); (btw, why are you doing ToActor again on line 27 after you just did it on line 25?) Line 27: self.angle = ToActor(self.parent):GetAimAngle(true);. It's not needed. Also, I'd suggest that you make variable gun on Line 20 local, like this: local gun = MovableMan:GetMOFromID(i); Same for actor on line 23. (Unless you need to use these outside of the script) The errors (most likely, unless you make sure outside of the script that they are not destroyed.): Line 49: self.Pos = self.parentgun.MuzzlePos; Line 62: ... self.parentgun.ID ... Line 65: self.targetpaintergood.Pos = ... Line 76: self.beamparticle.Vel = ... Line 77: self.beamparticle.Pos = ... On line 37 you have done some checks but there are some flaws: First, I'm not sure if this is adequate: self.parentgun == nil or self.parentgun.ID == 255. If i remember correctly, even though the object is destroyed in game, you can still read non-nil values from the pointer (the game does not set the memory to 0 where the pointer points to), so you will need some function through which the game can tell you if it has destroyed the object or not). And even if you can read from the pointer, it is illegal to read from deallocated memory. (Can crash or if not then your script might be working with invalid data) (If I'm wrong, somebody correct this). I guess MovableMan:IsDevice() will work for devices. Not sure what to use with emitters though... EDIT: Grif wrote: IsParticle, if it's an unparent emitter. Second flaw is that even though you do self.ToDelete = true; on line 40, the script still contines to run to the end before it's destroyed. You must extend the check to whole script, or alternatively return; from function. But I'd suggest enclosing all parts where you use parentgun or parent, inside the if check. Do that and add checks for the error parts too and it should work. Also, about Agetimer on Line 7: self.Agetimer = Timer();... You don't need that, you can use the already existing Age property like Grif said: Grif wrote: ...self.Age:IsPastSimMS... However, I'm not sure if you can use methods on properties of objects, or if MovableObjects inherit the IsPastSimMS method from their parent class. Anyway, it would make sense that Code: self.Age > self.maxtime I hope this covers most of it and that I'm not horribly wrong. But if I am, feel free to correct any of this. (Darn long post ) |
Author: | Grif [ Fri Mar 12, 2010 1:02 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
Quote: However, I'm not sure if you can use methods on properties of objects, or if MovableObjects inherit the IsPastSimMS method from their parent class. Anyway, it would make sense that self.Age > self.maxtime would work. that's probably correct, actually. |
Author: | ScifiSpirit [ Fri Mar 12, 2010 1:14 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
Could you or somebody enlighten us as to what to use for emitter death checks? I know IsActor and IsDevice but couldn't find IsEmitter. Or any other safe and reliable and proper way to do it? |
Author: | Grif [ Fri Mar 12, 2010 1:27 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
IsParticle, if it's an unparent emitter. There's no perfect way to check for attachables, or rather, to check that they exist, but there are workarounds possible. |
Author: | ScifiSpirit [ Fri Mar 12, 2010 2:29 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
Oh of course, thanks. I had forgotten. I was looking at MovableObject at LuaDocs, when i should have looked at MovableMan. Edited in to my post. That should be enough info for starters. |
Author: | PhantomAGN [ Fri Mar 12, 2010 7:10 am ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
Thanks for the terrific help, I'll be fixing this for a while. It's so much patchwork now that it's not even funny. Edit: A lot of this stems from general lack of understanding, for example, I do not know what the alternative is for line 27's redundancy. This makes fixing such things harder. Edit: Changed and updated, still not working, but also not crashing (just deleting self) http://pastebin.com/ChyRsiDG if MovableMan:IsDevice(self.parentgun) == false -- This is always false What's wrong with my method for getting that? It's a code lump, found in a few mods I use as parts-bins. I don't even really know how it works, just what the input and output are. |
Author: | Grif [ Fri Mar 12, 2010 3:53 pm ] |
Post subject: | Re: Yet Another Implementation Issue - now with added crashing |
It's always false because hdfirearms aren't Devices while held; they're attachables. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |