HerpeDerpeDerp
HerpeDerpeDerp
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
Regardless of whether or not this is a good way of solving the problem of references to removed objects lingering around, I would also just like to learn a bit about things like analyzers and source generators in general as I've never used them yet. That's why I asked specifically about analyzers. Even if they're not a good solution to the problem, I would still like to know if/how they could be used
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
But I don't trust myself to never mess this up and accidentally store an unwrapped reference somewhere leading to a possibly very hard to find bug
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
I'm making a game and in that game there are several types of objects that exist for some time but can be removed at some point. Many of these objects will have references to each other, such as a projectile keeping track of who fired it because it needs that information when it hits something. It is in theory possible to not have such references between objects, but I don't really see any method that doesn't have major drawbacks. Problems arise when such objects get removed as references to these removed objects might still exist somewhere and attempting to do things with these removed objects through those references can lead to all kinds of bugs. Simply flagging the instance as being removed and always checking the flag before doing something with the instance seems like an easy solution, although still very easy to miss some of the (tens of) thousands of checks, but many of those instances will be reused to avoid memory allocations and a simple flag won't do. The solutions I'm currently leaning towards is giving each instance a version number which is incremented each time the instance is removed. Whenever one objects stores a reference to another objects, it does this wrapped in a struct that stores the current version number (as of making the struct) of the referenced instance with it. If I try to get the reference from the struct, it first compares the current version against the stored version number and if they are not equal it won't give me the reference but instead just null. It is still perfectly fine for functions to pass references to each other directly without the wrappers because the removal of objects only happens at very specific moments so it suffices that those unwrapped references are just never stored.
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
And I need some weird rather specific rules. The types are allowed as type parameters of fields of certain generic types, but not of other generic types, for example
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
Which rule would that be? I don't see it
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
Thanks, I was not aware of that. However, I'm not interested in the public api, but rather in the private fields
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
I would be fine with declaring these interfaces and attributes outside the main project/solution
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
Or something along those lines
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
Are there any ways to work around this? Essentially I do not want to allow fields of types that implement a certain interface unless those fields have a specific attribute
21 replies
CC#
Created by HerpeDerpeDerp on 11/15/2023 in #help
Getting started with source analyzers
Hmm
21 replies