Problems others have already ran into

From Torch Wiki
Revision as of 15:42, 17 December 2019 by LordTylus (talk | contribs) (Created page with "= Introduction = Every day developers are working on either torch, or plugins for torch or just write mods for the game. In any of these cases you may encounter problems, t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

Every day developers are working on either torch, or plugins for torch or just write mods for the game.

In any of these cases you may encounter problems, that may cause problems you sent hours on googling, talking to people on discord and trail and erroring till you finally got the result you are looking for.

This is what this page is for.

If you have found any weird things in the game, you spent long on to get a hang on you may add it to this page to help other developers who the don't have to annoy people with the same questions you did when they run in the same problems.

Object Builders and the UI Thread

In order to create any Block, Grid, even Planet you need to work with Object Builders. Every Entity can create its ObjectBuilder for you. However creating an ObjectBuilder is quite expensive from a performance stand point. So you may attempt to do it on a separate Thread to not block the UI Thread for too long.

However ObjectBuilders have to be created on the Main thread. If you don't do that you run in concurrency problems where someone on Main Thread changes blocks of a grid for example while you grab its ObjectBuilder. There are two possible outcoms. Either you crash with a ConncurentModificationException, The Main thread crashes with the ConncurentModificationException or neither of you crashes but the validity of the created ObjectBuilder cannot be determined. So it is potentially broken.

If you just want to get one ObjectBuilder is fine, if you want to get a reference of many ObjectBuilders make sure to grab them in batches so that one Update-Cycle only has to create one or two of them. And not reduce the simulation speed by that much.