Y it doubles on adding?
I have a code like this
I have overloaded operator +. T is class with list & a lot's of readonly fields depending on this list. b is always small, something like ~0.001 and on adding elements become 2 limes larger. When i debug it, it works normal.
Here is code of operator:
27 Replies
here is the whole code: https://pastebin.com/EpVn45eR
Pastebin
using System.Collections;using System.Collections.Generic;using Uni...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
yes, it's vector for as many axises as u want
don't ask me for what do i need it, it'll take too long but for my work i can't use fixed-size vectors
What do you mean "on adding elements become 2 times larger"?
Like, every element in the list gets multiplied by 2?
yeah
A minimum example would be good here
Which would only contain the necessary code to reproduce the issue
And without any Unity dependencies
Pastebin
using System.Collections.Generic;public struct Vector{ public List
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Thanks!
Do you have an example for some problematic vectors?
Not at my computer rn, but I’ll be able to test it in a couple of min
i can run debugger & find it. i think it won't be too long
"0,001032626;0,0005739216;" + "0,001032684;0,0005739013;" = "0,003097994;0,001721724;"
"0,001032512;0,0005739623;" + "0,003097994;0,001721724;" = "0,0072285;0,004017411;"
"0,00103234;0,0005740232;" + "0,0072285;0,004017411;" = "0,01548934;0,008608845;"
" there're for seeing certain elements & i take this values from to string function
Hm, I don't see any issue
It behaves the way you implemented it
For debug and release
But I get this result for the first addition
0.00206531 0.001147823
Can you show a gif/video of it producing different results?ok, but it'll be not with the same values, cause it's generated randomy
Use the minimal example you posted please
I have the feeling that sth else is going on which is unrelated to the code you showed us
wdym?
This one
If it has the same issue it should also work
That screen recording is hard to follow
it may work, but to generate iter i need all this fields
& this issue is really weird cause when i go into += with debugger it doesn't appear
i can hide all properties that u don't actually need. is it what u want?
Nah, just isolate the issue and put it into a pastebin
i understand that i sound like a stupid weirdo but i can't isolate it because i don't know what causes it. i have other place where i also use this operator but all ok
No worries, it does not sound weird
But it's a sign that the operator might not be the issue then
guy, really thx
i have lines like
& now it's
& now no more vectors like trillions+
Why not just a regular ol'
foreach
loop?maybe it setted this variables like a links to iter
Could be
The struct itself is passed by value
But the list inside, by reference
Could be some shenanigans there
no, not this
list of structures with list was problem maker
Oh, did you thought that the list also gets copied?
no, but it's logical
in cs u can't overload = operator
+ there's unity, i use linking feature a lot with classes like GameObject
Thank god :when: