Jump to content

Photo

findEntity (deadMonster) == Bad Object?

bug dead monster bad object

  • Please log in to reply
No replies to this topic

#1
Davin626

Davin626

    Newbie

  • Members
  • Pip
  • 12 posts

Hey, if anyone's still on this *Foorum* (I just discovered this game last year), I have a mod I'm making, a good fun romp through a 12-level dungeon.

 

One thing I'm having an issue with is a "Bad Object". Apparently if a monster is killed (by the engine, e.g. normal damage, not via monster:destroy() AFAIK), and I try to get its data the same frame, it crashes. Sometimes. Arbitrarily (1% chance?).

local entity = findEntity (id) -- Finds a seemingly valid entity
local name = entity.name -- Crashes, sometimes

So it may be something like a Lua-esque dangling pointer - thinking it's a valid pointer/reference, but to data that is now overwritten. (That's just a guess, and just one possibility).

 

Is there a good way to work around this?  I've tried "if entity == nil", "if.entity.id == nil", and "pcall()" (Lua's version of try-catch, which doesn't exist in this implementation).

 

As I said, "findEntity()" thinks the entity is valid, but any attempt to further verify that (entity.name, etc.) crashes.

Googling - Lua "bad object" - doesn't help.

 

This currently seems to be specific to one script I'm using, but one that I really don't want to abandon. (Mwahahahaha! Got some nice tricks in this mod).

That script does cache old data, and is perfectly happy with *handled* failure (using cached data instead of fresh data), but this has no handling, just a crash.

 

Davin






IPB skins by Skinbox
Page loaded in: 1.014 seconds