Jump to content

Object reference count error & Crashes


Phodex Games
 Share

Go to solution Solved by Phodex Games,

Recommended Posts

Hey :)

its me again. I had a similar problem some time ago, but this time its diffrent and I still did not found a solid solution. So when I tried to load a new map like this,

world:Clear()
Map:Load("Map path") 

it just crashes, without any error or anything. After some testing and deleting diffrent stuff step by step I got a object reference count error. This is pretty frustrating :(. Well I know its due to my code, but sometimes I lack some bascis as I learnt the whole coding stuff by myself. I nailed down the problem by trial and error. It seems to be my AI/Characters and weapons equipped to the player and the AI, had no energy yet to do deeper research on this. I am just wondering how you generally deal with such an issue. I have this problem very often, if I want to release an object it just crashes (for example it is playing an animation atm, or used elsewhere in code), so I need to fiddle around, using self.entity:Hide(), or do some workarounds to prevents this. I know there is self.entity:AddRef(), but how to best use this to prevent my game from crashing? I am a little bit helpless and so close to the release, I need to fix this! <_<

Link to comment
Share on other sites

The best way to change map which I learnt is change the value of changemapname variable (it is a global one) in the main.lua instead of using Map:Load() in any script.

This prevents game to crash in most cases. I got this problem before when I use Map:Load() in Script:UpdateWorld() or Script:UpdatePhysics(), loading map like this will cause errors like "assert error" or some entites not found (nil) even they are in code.

Hope this help :)

  • Like 1
Link to comment
Share on other sites

It depends on where you are calling this code. If you are calling it inside an entity script function, the results could be disastrous because you are telling the engine to delete an entity that is currently having a script run on it.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

2 hours ago, Josh said:

It depends on where you are calling this code. If you are calling it inside an entity script function, the results could be disastrous because you are telling the engine to delete an entity that is currently having a script run on it.

I think, the engine should call addref before calling a hook in a script and release afterwards. This way this could never lead to a problem like this and there would be no harm in doing so, since in this event the world would first release its reference and after the object was done with its current hook it would be deleted.

Link to comment
Share on other sites

  • Solution

I fixed the problem on my own now. After disabling various things and doing the map change in main loop I could nail down the problem. It was caused by many diffrent sources and turned out to be pretty complex, still could fix it luckily. Thanks for all who posted, your information was helpful indeed.e

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...