View unanswered posts | View active topics It is currently Mon Jan 13, 2025 6:30 pm



Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
 Yet Another Implementation Issue - now with added crashing 
Author Message
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Last edited by PhantomAGN on Sun Mar 07, 2010 7:09 am, edited 1 time in total.



Mon Mar 01, 2010 6:44 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Mon Mar 01, 2010 9:55 pm
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Fri Mar 05, 2010 1:50 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Fri Mar 05, 2010 3:43 am
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post Re: Yet Another Implementation Issue
Hmm.
I'll have to check that, I never considered something like that.


Fri Mar 05, 2010 4:45 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Fri Mar 05, 2010 6:08 am
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Fri Mar 05, 2010 8:55 am
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Thu Mar 11, 2010 4:55 am
Profile

Joined: Sat Jun 16, 2007 8:04 pm
Posts: 42
Reply with quote
Post 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
would work.

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 :P)


Last edited by ScifiSpirit on Fri Mar 12, 2010 2:16 am, edited 2 times in total.



Fri Mar 12, 2010 12:42 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Fri Mar 12, 2010 1:02 am
Profile

Joined: Sat Jun 16, 2007 8:04 pm
Posts: 42
Reply with quote
Post 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?


Fri Mar 12, 2010 1:14 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Fri Mar 12, 2010 1:27 am
Profile

Joined: Sat Jun 16, 2007 8:04 pm
Posts: 42
Reply with quote
Post 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.


Fri Mar 12, 2010 2:29 am
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Fri Mar 12, 2010 7:10 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Yet Another Implementation Issue - now with added crashing
It's always false because hdfirearms aren't Devices while held; they're attachables.


Fri Mar 12, 2010 3:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.054s | 14 Queries | GZIP : Off ]