SEModCommunity / SE-Community-Mod-API

Space Engineers Community Modding API
GNU Lesser General Public License v3.0
60 stars 47 forks source link

BUG: CubeGridEntity properties not setting or changable on restart. Takes awhile for setting properties to actually work. #134

Closed Tyrsis closed 10 years ago

Tyrsis commented 10 years ago

This started happening after the internal data refresh change, but now I can't seem to get around it. After awhile setting properties on cube grids is fine, but right after a restart, it takes awhile for properties to actually set.

Properties are settable in GUI though, but not via API. If you do a: List cubeGridList = SectorObjectManager.Instance.GetTypedInternalData(); (github is removing the braces)

Then try to access a cubeGrid in the list, the properties are all right. The problem is if I set or change anything (like setting beacon text or changing BuildPercent in my situation), nothing actually happens. BuildPercent doesn't update in game, nor does beacon names.

Eventually after awhile stuff starts working, but I'm not entirely sure what is triggering that.

Tyrsis commented 10 years ago

I put in some logging. You can clearly see the issue in the logs after I threw a debug statement in the property set of customname of a beacon (terminal block) for example: http://pastebin.com/56Mgk4Yy

For some reason it's using the wrong data in CustomName when setting the value. It's using it's old value and not the value I'm setting in the property.

Tyrsis commented 10 years ago

This also brings up an interesting problem. The way you're setting entity properties relies on values that need to persist across threads (the main game thread, and the plugin / extender). While this works with 1 plugin, what happens if there's 20 plugins that all decide the change the name of the same beacon? While the value will be set to whoever sets it last, the issue I see is race / thread problems. If 20 threads update the same beacon, it'll most likely lock up / exception, as you have multiple threads modifying the same value.

This can setup an issue down the road that's a bit hard to diagnose.

Tyrsis commented 10 years ago

Yeah so it's the ObjectBuilder object that is being changed. I was able to fix it by using globals instead of using the values in ObjectBuilder, but this doesn't seem like the best idea. I will leave it at this until you get a chance to look at it.

chessmaster42 commented 10 years ago

This is now completed and in the latest dev builds. Please verify the fix or post more details if it is still broken.

Tyrsis commented 10 years ago

All good.