Hidden Dangers of Range-Based For Loops // Bug Hunting

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
yeah we had this bug where things just went like things weren't um behaving well when we were deleting like uh entities so i want to fix that because it's a little bit annoying and i had a quick look at it last night and i couldn't solve it so this will be interesting to turn into a little bit of a video or a stream or something like that um yeah i'm gonna just light my little contraption those of you don't know i have this lovely like frying like cast iron skillet style frying pan with like a tea light underneath it and then there's like some stuff that it's melting just gonna go ahead and introduce that to the stream uh so i gotta light that so i'll be back i managed to create some fire it's lit it's gonna it's gonna fry nicely and we're gonna get on with some some nice duck hunting i mean bug hunting so um as i mentioned i actually have no idea why this is happening and i wasn't lying uh this isn't gonna be like one of those fake little i have no idea what's going on but really it's just all a show no unfortunately i wish that was the case because that would make my life easier but no i actually don't know what's happening so um basically this is the bug i'll show you guys the bug so that you're you're aware of the bug but basically the bug is uh every time i say the bug by the way you have to take a shot of um of orange juice because this is a pg stream right so um yeah so basically the problem is that if we try and delete sponsor there's actually a few bugs like for example sometimes i can't click on stuff here sometimes stuff just disappears this scene hierarchy panel has a few bugs happening which is a bit annoying but anyway like look at this i can't even select this what's going on that's what happens when our audio guy decides to do ui if i delete this sponsor model as you can see it does not get deleted it's gone from here but like what is this stuff it's suddenly gotten bigger possibly because it's been like unparented or something and like the thing is it's kind of weird because it's still like an entity i can move it and stuff uh it's obviously being rendered it looks like it should be a real thing and i mean more so if i click on it to like select it you can see it is actually appearing here so the thing is um it's it seems to be like still in the entity component system and it still seems to be like a valid entity and everything it's just not showing up in the scene hierarchy panel why isn't it showing up in the same hierarchy panel well the way that we actually show entities in this panel here is kind of dependent on like the where they are in terms of their own personal hierarchy of like parents and children all that stuff so if they have no valid parent then as far as i know i think they're not going to show up in the hierarchy so clearly deleting that sponsor entity has in fact left some orphans here but they are i don't know why they exist so there's a few few things i want to do to kind of take a look at this right the first thing is i don't like the idea of not knowing what's going on i think that when you're you know programming and when you're doing all of this when you're setting up like complex things like game engines it's always really nice to write some tools for yourself so that you can actually see what's going on at all times that's kind of important and so that's what i'm going to do my pillow fell over that's all right it's not visible on stream anyway so it doesn't matter so basically what i want to do is i want to make a new kind of panel i want to make a new kind of i want to make like a debug kind of entity component system panel type deal and the purpose of this is just to dump like literally just raw entity information because clearly something is surviving and i want to be able to inspect it as best as i can this shouldn't take very long uh i'm just gonna go over here i've moved my solution explorer to that side because i think it's less useful than the code to look at i'm just making some new files no big deal so we're going to call this like ecs panel because it's just going to this is just for kind of a debug and it's just going to be a way for us to like move this a bit um for us to be able to just dump some info so let's go ahead and name space hazelnus namespace hazel class ecs panel um we don't really need to do much so i will add a like a scene as like a context so that we can see what's up i don't think we really need that on i'm going render we'll open and we'll obviously keep track of that context and maybe like a set context would also be appropriate in case we switch scenes to the run time or whatever all right so let's quickly make all of this stuff doing some speed running programming here um context context will have no destructor for now and on i'm going render so i am going begin acs so we'll i guess we'll call this ecs like debug or something acs debug panel maybe uh and then we're gonna type in open like that this is just so that we can close it and then if it's if open is false then we just return this is just a way for us to show the panel and not show the panel if we don't want to include hazel ui i am oh hazel i'm going i'm gooey all right and set context um this will this can just be implemented here context context uh i'll call this context i have three eggs we already talked about that keep up so let's see so we've got this panel that's good so yeah so basically what i want to do here is copy kind of what the scene hierarchy panel is doing because it's doing all it's like rendering all the entities but um the thing is this is not going to be a hierarchy and that's kind of the point i want to just see the raw view of everything obviously everything is kind of a flat list it's not really a hierarchy that doesn't make much sense well i know i mean i i guess theoretically it could be but it's not right because energy component systems store like just components as like just arrays so there's no hierarchy there's no like linked list or some kind of actual tree data structure it's just a list it's just like a vector so if we take a look at like um yeah i guess online render and then we take a look at the scene hierarchy and context and then what does it do there's a whole bunch of i'm going code here but eventually we go through this and you can see we kind of go through the registry and we just view all of this stuff but i actually want to a better place to start might be the serializer because the serializer actually like takes a look at um it just actually you know iterates through every component because it has to serialize it or every uh entity or other so where does it do that so serialize serialize and then you can see it goes through every id component so it's almost perfect it doesn't go through every component because what if a component what if something's missing an id component very unlikely and i don't think it's happening here but still kind of possible i guess but whatever so first of all we have to add um this ecs panel as a friend class because the registry is private and then if we come over here let's just go ahead and go through this so m context so if context just in case it's null in which case the panel will be blank we're going to go through this okay so now we have every single entity so what i want to do now is very simple i want to just list it i want to just have a list of these things for now now we could have some kind of like table or whatever i don't really want to do any of that i just kind of want a selectable list of things now um now for the selectable list situation we could have tree i guess there's something called i'm going selectable which you can use this is probably a good time to use it so let's try and get like a uh const order name from it which will be entity so let's make actually we'll call this like e and we'll do entity uh entity equals e and m context dot raw because i think this once this uses a pointer roll pointer just because it's we could have used a weak graph now that we have weak references but um it just uses raw because it's it's not taking ownership of it it shouldn't be keeping it alive it's just like a way to access it so entity.get uh can we just get name so we can't do name so i'm just gonna whoops accidental russian as usual uh so we don't have names so i want to get the name right so let's go ahead and just do const auto sorry console city string name uh that'll be the const version and that will be uh scene registry get uh tag component dot tag why are you upset whatever we'll we'll figure out why it's because it needs this and then we'll have an unconstitution as well in case we want to modify it now i don't know if entities are guaranteed to have a tag component that's kind of the issue and maybe that's why it's not like might not be a good idea to do i don't know though entities do they have to have a tag component well possibly like i guess yes because when we create an entity i'm pretty sure it always like adds a adds a tag component to it no we'll actually create child entity if it doesn't have a tag component if it doesn't have a name in this case it doesn't actually add a tag component so it's possible it doesn't have a tag component so let's do this for name um let's just make a static uh an inline static std string uh no name um [Music] which will make uh no name michael's null i don't know now's a bit weird but whatever no yeah because it's not null it's just unnamed let's just do unnamed and then what the reason for this is that we can expand this name to be a bit a bit better now so we can do like uh has components i don't know why i'm using this to be honest so how's component tag component so if it has component tag component then we return get component tag component dot name mod.tag otherwise we return [Music] no name because it returns a reference so we need to return something valid and yeah we'll do the same thing here but obviously it will be const all right brilliant so going back to ecs uh panel now we can do entity name which is fantastic so now we've got the name name dot c string uh and i mean bull selected like for now we won't be able to select them i guess but it would be better to select them in some form so we probably have to have like an array of so we'll we'll select it so this will have an index and we can just keep track of the the selected entity i assume so let's just do like entity selected entity that should be an invalid identity by default um so i think the way that we well bull selected is going to equal m selected entity equals entity so in that case it's selected now uh we do have to give it this because if we decide that it's now selected right so if i guess if that then selected but i don't really want it to be because it will set selected to be that and then what are these selected flags anyway disabled allow double click yeah i don't care about any of this um so we'll just do zero or whatever and then there's a size which i also don't care about so if it's selected then we'll just do this like we don't really have to we don't have to worry about the boolean being written to so this just lets us select it right it's pretty simple and then i don't like we can't really deselect it at the moment but i don't care about that either so we should now be listing all these names so this is fine but like um i kind of want to add a little bit more information to this so like i want to have the good as well so let's just do std string like label and then we'll make this fmt format so we'll do the name and then maybe the id so name and uh entity get uuid and then this label is what we'll actually use here okay so going back to entity uh editor layer that's what i meant going back to editor layer let's um go to where are all of my panels there's so much stuff here that needs to be cleaned up optimization october where are you so asset manager panel open let's do like um ecs panel open and then i guess like this is lame though where's like the scene hierarchy panel where's everything at the moment we're a little bit all over the place because we can't like even close these things but this is like a bunch of panels so i guess i'll just make it here um and then we can make it a scope sure it doesn't really matter ecs panel i have to include that so ecs panel we'll call this ecs panel i'll call it ecs debug panel because it really should only be used for debugging like just what we're doing now yeah so see there's a lot of set contact stuff that needs to happen so i guess we'll kind of follow along with this um [Music] and we'll just duplicate the scene hierarchy panel except yeah we can pass in uh a cs debug part acs panel open maybe i'll just rename that to debug panel uh set selected wear and care about i guess it would be nice to select it in there though yeah that would probably be nice let's do that actually so we'll add a set selected [Music] which doesn't exist yet obviously but um this means that we can actually mouse pick it [Music] so uh but we won't let it pick us probably maybe we could do that though we could try and click on it and then it was selected and that would be kind of cool but i won't i probably won't bother with that for now so set context to run time scene okay good so i'm just making sure that they're both there basically okay so set selected isn't a thing ecs panel so what we'll do is we'll have a void set selected uh and then this is pretty simple uh this just takes in an entity i think right and then just sets m selected entity to entity and that's probably it and then that should obviously reflect here so let's see what we've created now oh there's no way to open the panel actually so back in the delay let's go to view so we have like a view menu um begin menu view right and then we can do like um i might add like a little separator because these are like debug panels well so is asset manager though uh whatever um ecs debug did we give it a title yeah acs debug wait let's take a look so this is coming along nicely for those of you uh playing along um it's uh mostly melted now smells amazing it's a pity that i can't show you guys what it smells like but you're gonna have to take my word for it first time catching the stream your boy nachin how's it going what are we doing today we're solving some bugs we're bug hunting uh we've got a weird bug where sometimes when i delete like a whole uh like cluster of entities what's with this like i swear it was did not take this long yesterday because we're in debug so we're running a bit slowly but anyway sometimes when we delete stuff it doesn't delete all of it and it seems to like do weird things now i have a feeling i know why but i'm also taking this as an opportunity to get to get my uh my crap together if we take a look at sponsor so this is the what i'm talking about so if we go view an ecs debug apparently it's true already why is it true i thought it was false by default oh i can't even uncheck it for some reason what oh lol open that was weird so we were um yeah we were setting the actual like pointer into the into the thing so of course it's always true and by changing it i don't know i guess we weren't changing it very well i don't know what's going on there a little bit weird because you're supposed to pass in a boolean which is like one bite and we're all passing in like a eight byte pointer so it was probably screwing with the pointer when we were checking it but it was true because of course it wasn't zero anyway so if we now do ecs debug so you can see we have like all of our entities listed out here which is pretty cool that's exactly what i wanted so let's just kind of dock this over here and i'm going to open up that other scene which should trigger a yep so it's changed as you can see it's just loading the meshes and stuff in the meantime but it's already loaded the scene hierarchy which is cool so this is like a flat list of all of the entities that we have in our scene right i might just try and uh make it a little bit more visible for you peeps just lining that up with the face cam so we have um we have all of these entities right and uh we should even be able to it's hard to see because the highlight color sucks but when i'm clicking on this you can see it's actually selecting them here it's almost more visible on stream um so uh but i can't if i click it doesn't select them here but if i select something over here uh okay it doesn't work if i selected the scene haracker panel but if i click on something in the viewport it selects it here which is pretty cool so the idea is right what i'm doing is i'm deleting this but clearly they're not all being deleted so let's see what happens this contains 25 different entities right so obviously i'd expect like 25 of these to disappear but they're not disappearing but anyway so let's try and delete spawns off see we we did delete some but look how many are left and we can't see any of them here so see this is nice as like a debug feature because we've already given ourselves the ability to be able to see what is actually going on as a programmer i want to be aware of the data because the data is everything so here is the data and we can see that we still have these so they didn't get deleted properly i don't know why though um it's very strange because i think another thing i was doing uh was i was actually like logging um something like impossible to bring up the taskbar sometimes uh yeah so no this is rubbish i was logging something else i was logging like all them being deleted let's go ahead and okay i want to do a couple of things actually i want to make sponsored the startup project so let me just find like the age proj and we'll make uh scenes sponsor demo i think we'll make that the startup scene and then if i go into scene let's go ahead and try to figure out what's going on so this is the this is the function of this is the function that we're that we're trying to fix right so we destroy entity and clearly its goal is to destroy uh entities and we have the ability to exclude children which we're not doing right so we're issuing a command to destroy entities this is happening from i think uh the same hierarchy panel now it's hot well yes but it's happening from i'm not sure why it's not popping up can i from all projects references from all program so here it is so edit a layer destroy entity this is where it's happening so this is the command that's destroying it this is when we hit the delete key so it's passing it in with exclude children as false meaning the children are included and then what it's doing is a bunch of stuff that we don't care about my can my biggest concern here is that something is uh messing with this list because we're iterating through this list and we're recursively deleting all of this stuff but the thing is if this is messing with the list then you know you have to be careful with 4-h loops because if within the 4-h loop if you're modifying the iterator that you're using it's very bad and most languages like java and c-sharp will actually throw like concurrent modification exceptions or something like that maybe not concurrent because that implies kind of multi-threading but uh it'll they'll have some kind of exceptions that they throw because like hey man you can't do this if you have a regular for loop it's fine usually because you just have like an index and you're just accessing it by index but this can invalidate the iterator if you modify this now the simplest way to prove that case because that's kind of like my first uh my first guess is what i could do is copy the list because if i copy the list then it doesn't matter what i'm doing anymore you know i have a copy of it i can use one copy to iterate over it and another copy to modify so again i don't know i don't know if this is the solution like well first of all copying is obviously we want to avoid that if we can but these are just uuids it's some of the biggest deal in the world and this is a delete function which we call like well i mean throughout gameplay i guess you could be destroying entities all the time but at the moment it's just like we're hitting the delete key and that's it so let's just see we're gonna use this as like a test so auto children equals entity children i'm just copying this what is this as i mentioned a vector of uids so we're copying our children let's iterate through this copied list right so the deal is uh when this actually destroys it it might be it might be modifying this children list or something might be happening but it's not going to be modifying our copy because it can't so let's just see if that does anything i'm not sure that it will because i don't really see any code i mean we have removed child ah remove child does remove something right so it is clearly erasing something so it's possible to remove child is messing with it actually that would make sense okay never mind this is beginning to seem likely so let's let's see if this is actually the cause of this you guys can't see that but she's just she's just chilling like you're sitting on my speaker what do you want attention again glad did that you've got so she's so needy lately needs her journal time don't we all so let's try to delete this so i'll bring up that ecs debug panel again let's try delete sponsor oh my gosh they're all gone solved okay so moral of the story is be careful when you have uh vectors like this right and you and you're actually like within the for loop that you're for reaching over you're modifying this itself again it's not that apparent because this is like a whole recursive hierarchy thing but it's very possible obviously that somewhere within this in this case it was actually over here but the thing is this only happens for the first iteration which is then false so within this for loop technically we shouldn't be doing this so i'm not 100 sure why this happens it's possible that registry destroy which is actually an ant function maybe within this somewhere it calls like some kind of callback and then that callback removes it but overall it's very strange let's kind of try and wrap let's try and hunt this down a bit more so if i go to uh and finance it by uhd okay let's go to destroy let's go to remove child because we know that modifies the vector we can see that it's erasing the children and well i mean even set parent does that but like this doesn't make sense because again it does this at the very end and it does this for the first time so i'm not sure unless it's being indirectly called from somewhere else let's just try that again i shouldn't have closed it because then i could just load it again but yeah i don't know a bit weird oh to be a cat and be chilling on a massive speaker that's funny yeah cats love my massive speakers it's just a cat's name in russian with a little cute smile yep well yeah alefka he wrote alifka that's my cat's name olive but like it sounds better in russian and i talked to her in russian because i mean who wouldn't right uh so if we bring this back up um well it doesn't really matter but like if i try and delete this let's see if that remove chart see it doesn't even happen anywhere man so what is modifying it something is modifying it but it's not this so let's not remove child what what else modifies this children list and actually like modifies it though well the other thing is i guess find entity by uuid also has to iterate through no that doesn't really iterate through children though this is such a weird case right because i don't know what is modifying this list but clearly us making a copy fixed it so that makes me think that yes something was in fact modifying the list and there's no like race conditions here this is all single thread like all of this work so it's it's and it was definitely reproducible 100 of the time so this isn't some weird thing that's happened this is actually like something weird is going on and it's like within like a few functions here again i might my my guess is something to do with this but but i'm not sure that it is because like this is the loop that is recursive so destroy entity calls itself and then it goes through everything right and it's not going to have any children in this case uh this will be false so it shouldn't be doing a remove child and all it's really doing is this i think um and it doesn't do it doesn't do a roof child because the entity itself gets deleted but this removes itself from parent if it has a parent but it didn't even have a parent so it's all very strange like i legitimately don't know what is happening onscript component destroyed that doesn't shouldn't do anything with children is edit a scene so that's um uh this is if it's the run time so it's the runtime we also have to remove it from physx uh but then there's this thing child id because like the second so we're iterating through this we have a child idea we're inside of this iterator and then we come here and then we go through everything again and then we get the iterator again but the thing is none of this should be removing it as it like from the children list right i mean we can also i guess we can also put a breakpoint into here i mean this happens all the time though unfortunately okay let's let's um put a breakpoint here let's go back to hazel i'll reload that scene so now we get sponsored back and we have all of our entities and now let's just delete like this that will trigger this breakpoint and now i'm going to go to this children vector and then put a breakpoint there and see what's causing that so yeah so destroy entity gets it from here yes and then yeah it gets it from there again and it's always getting it from that line line 15 26 which is this so as far as i can tell that's the only thing that's getting it and and like i mean it shouldn't the iterator itself should be fine because it's not modifying it it's only reading it right like it's never removing children because that actually happens at the end like all in one go kind of oh hang on hang on here's a lambda ah that's the scene hierarchy panel oh so we've deleted everything now think we're done yeah we're done we just deleted everything okay let's quickly go back to what we had and i want to like let's just do hsn core one child count so we'll see if this progressively gets smaller because my guess is this should always be either 0 or 25 until like the very end so let's take a look at that because again my suspicion still is that something somewhere is probably removing it like that's kind of the only explanation that i have unless i'm just again wrong and i mean i'm i'm i'm wrong like 51 of the time so you've upgraded to the computer and you've got upgraded to the computer she can barely barely see but but she's there all right we're back um so oh we've already got sponsor look at me opening it like a full so uh yeah so we expect this not to work and as you can see it hasn't deleted everything so um [Music] so why hasn't it worked let's go to here where's the delete where did the delete happen here child count 125 and all of these are zeros yes okay that's not i didn't exactly do what i wanted though let's um i guess what i wanted to do is within here i want to just verify that my size is legit because that because that did it like it said zero because all of the all of the children with no children so all of the kind of um leaf nodes they obviously don't have anything so that's fine but yeah log size of children in the loop yep that's what i'm doing sorry i haven't been reading chat too much because i've been too focused man this startup time though indeed but i i don't know i was debugging this last night i was running it in debug mode same as now but it was way faster so it's weird i mean now it's also loading sponsor i guess whereas before it was loading another thing but still that this uh startup time is a bit depressing we can compare it to release mode in a minute because that's like a couple seconds keep trying to load sponsor um let's delete this and i should stop the whole rendering entities i keep running i was just logging how many meshes i was actually rendering but yeah so yeah so it's a consistent 25. the one is because um the one is because of this because sponsor has one child which is not zero just because it happens to be like an extra parent in the hierarchy in the actual in the actual fbx file but then here they are so it's always 25. so what gives why is it just not deleting everything or why are these still here and why why are they still here and why does this fix it like making it a making it a cop making a copy of it fix it the only way that makes any sense is if something modifies children but nothing seems to be modifying children okay new plan new plan let's make this a for loop instead of a for each loop right so i'll make this for uh i equals zero or let's let's do it properly size t i equals zero i is less than uh we'll get we'll we'll leave that copy there but we won't use it size i plus plus and then we'll do order well this is the child id child we'll just replicate it perfectly so we'll do child id equals that and then that's the thing so same exact thing but it's a it's a it's a regular for loop why is this different because we're just keeping track of an index now and it's not dependent it's not like an iterator and that that is an important distinction but if you're on the forward backwards that's a interesting concept all right so let's delete this with the ecs debug panel up oh it worked excuse me but apparently like four h loops are just broken is there like some kind of weird thing where you can't iterate you can't get a for each loop within a for each loop is that a thing like is that actually a thing in c plus plus am i not supposed to have a for each loop inside a for each loop because i mean well the thing is it worked when i copy it though oh but every step of the way copies it like a nested for each i'm almost certain it's okay well yeah i mean i've never run into this before but that that seems to be like the like why is this broken if it's a 4-h loop like if it's a range based for loop so what was it auto child id and to see children like this i mean i am retrieving it every time but that's okay oh hang on oh maybe i figured it out guys maybe i figured it out i think what might be happening is i'm i'm removing entities from ant yeah and i since i'm removing entities from ant the component memory might be changing and so this might be pointing towards something like it's not necessarily fixed in memory this thing obviously when i do this i'm retrieving it every time like i'm i'm calling get component every time but if it's in a 4h loop like this as an iterator it's possible that it's not doing that i'm not even sure how i would test that i mean i could get the memory address of it and see if it's changing i guess so let's try that so memory address and then we'll just get whoops this let's let's check this out this is possible actually because i'm sure ant or entity the lab the entity component system does some housekeeping possibly and it could be shifting components in memory as they get deleted why don't you just use the normal for loop well i'm happy to i just want to find out why this is happening i'm not satisfied with just being like yeah okay i guess i guess that's just how it works because this needs to be an explanation for it you know as a computer scientist i'm very much interested in what's going on all right so that seems to have worked uh so that worked yeah that's fine because i was using a regular folio but let's take a look at i'm just printing this garbage let's take a look at uh the memory address this one's different but we expect that one to be different oh no it's not the same look how many times it changes there should be three of these right no wait wait why hold on okay i know i know a way to test it for sure this is how we're going to test it the this is how we're going to test it so what we expect is uh that what we expect let's just add a little level here so in level equals zero i mean i'll see why i'm doing this now i i want to see what level because the the thing is at one given level if we're iterating over it it should never change memory address right because obviously this is a recursive thing which means that we go deeper and deeper into it but then obviously if we've stepped into this function again the children that it retrieves is for this entity so it is a different set of children so of course it would be a different memory address what we are testing for is that within the one for loop this has to be identical this memory address if it's not then yeah so the reason we use this level thing is because we're going to add level plus one every time we step in recursively and that way we'll just see like what level we're at and all that stuff so um what we'll do is let's just do like uh l and then i'll write the level here and then uh we'll just do address that so we would expect the same address for the same level if they're different levels then that's fine if they have different addresses obviously in fact they they will have different address they need to have different addresses because otherwise it doesn't make any sense so that's my hypothesis let's test it out alif is gone alive nah she's audi she's had enough of my plus debugging right if we bring up uh unfortunately i'm still printing this but let's try and delete this now and then we go back and then again remember we're looking for same address different levels rather oh interesting so level zero we have a one address and then this you can see the address is constant until it's not and we are still at level one we only move on to in fact we don't even have a level two why don't we have level two oh because we don't have a level two because they don't have any children right so these are all leaf nodes so that's why we have two levels you can see guys that halfway through this over here the address changes this is within the one for loop and then it changes again so ent actually shifts this vector in memory twice during this iteration thing that's why it doesn't work however why our solution works for a number of reasons is because if we actually were to copy this like we just did if we now look at the memory address of this child vector then it will 100 percent be the same it will not change because we've made a copy of it and remember none of the we're not modifying that vector it's just the physical vector in memory is moving we're not modifying the vector at all it remains size 25 the whole way through yeah we've we actually tested that earlier but also i know it's not doing that because nothing's removing anything and nothing's clearing the vector it gets cleared at the very end what doesn't really get cleared the whole entity actually gets deleted from memory along with all of its components and that vector is inside a component so that's what's happening so now if we take a look at this again delete it and go back to this quickly i need to stop printing this um let's find it then check this out this is the difference so see now level zero has a different vector memory address but then level one has the same address the whole way through all 25 entities that's why it worked okay that's why it worked when we made it when we made a copy of it so it wasn't because we were modifying the vector we weren't it's because the vector was being moved in memory and we had that one memory address reference so if we use a 4h loop it doesn't work so how do we fix it well use a a normal for loop why because every time we use a normal for loop it calls dot children yeah so this has a constant size of 25 which is fine we don't that's not going to change ever that's fine we're safe to retrieve it like this but then this this little blob over here we get it each iteration and since we get it each iteration we get the most up-to-date memory address because going through this code obviously it looks up the component inside the registry inside the entity component system okay so that's a bit of a tricky bug definitely a bit of a tricky bug i think i might make a youtube video out of it so you guys should say hi to youtube right now but um yeah this is this is definitely a youtube worthy stream i think it's probably quite uh satisfying and interesting to figure out the the bug but uh yeah moral of the story be careful with your memory always think about the memory because always think about the data because the data is coming from the memory and obviously if that moves then like there's a a whole kind of situation right so it's important to kind of be aware of that i guess so yeah that's the solution i'm going to leave a note here no don't don't make an engine
Info
Channel: The Cherno
Views: 36,881
Rating: undefined out of 5
Keywords: thecherno, thechernoproject, cherno, c++, programming, gamedev, game development, learn c++, c++ tutorial, game engine, how to make a game engine, game engine series, bug hunting, fixing bugs, c++ bugs, for loops, range-based for loops, for each loops
Id: U7nXZ3woQig
Channel Id: undefined
Length: 43min 35sec (2615 seconds)
Published: Mon Nov 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.