Jump to content

  • Log In with Google      Sign In   
  • Create Account

Oberon_Command

Member Since 07 May 2003
Offline Last Active Yesterday, 10:39 PM

#5301635 When you realize how dumb a bug is...

Posted by Oberon_Command on 20 July 2016 - 04:38 PM

C++ allows overriding your parent's privates.


With public methods? That seems smelly. In that case, maybe this post should be in the "why didn't somebody tell me" thread.
 

[edit] Wait... How does Callee not generate an error when it calls a protected function??


In the actual code, Callee is a method on a friend class of Base (but not Derived). Thought it would be simpler to omit that. This isn't code I'd expect anyone to run through a compiler. ;)
 

[edit2] how are you passing a Derived& to a function that takes a Base*? :P


Whoops. Fixed.

Anyway, upon further reflection, this may not have even been the problem. That would be in line with what I get for jumping to conclusions after only 15 minutes.


#5301597 When you realize how dumb a bug is...

Posted by Oberon_Command on 20 July 2016 - 12:30 PM

Ran across this one in production code 15 minutes ago:
 
class Base
{
protected:
   virtual ~Base() {}
   virtual void MethodThatDoesAThing() = 0;
};

class Derived : public Base
{
public:
   virtual void MethodThatDoesAThing() override;
};

void Callee(Base* base)
{
   base->MethodThatDoesAThing();
}

void Caller()
{
    static Derived derived;
    Callee(&derived);
}
Surprisingly, VS 2015 compiles this without complaint. I would have expected this to be a compiler error.


#5300224 Does Object Pooling with a Vector in C++ have problems with memory?

Posted by Oberon_Command on 11 July 2016 - 12:39 PM

A lot of the comments here are missing one particular use case that the OP hasn't articulated, but is nevertheless around. Suppose you want to store a bunch of data in a contiguous container, but systems outside the one that owns the container want to access individual data, so you need some way to identify those individual pieces of data. You could do this with a pointer, but that requires that the individual data be fixed in memory location. You could also do it with a handle (or even a raw index), but that requires that the individual data be fixed in location relative to the start of the container. Or you could use some kind of mapping system like a hash table, at the expense of performance. An object pool like the one OP was trying to implement is useful in this case. It just isn't useful for the same reasons or in the same cases at it is for managed languages.

Whether OP actually has a use case for such a system is, of course, another question, as for small objects where ordering and location don't actually matter, keeping a flat vector and using the erase/remove idiom (or even straight "swap and pop") is a better solution.


#5299724 Does Object Pooling with a Vector in C++ have problems with memory?

Posted by Oberon_Command on 07 July 2016 - 08:29 PM

Okay.

What works well in Flash is not necessarily going to work well in C++. The object pool pattern being described is specifically used to work around the garbage collector to get control of memory again. That is not necessary in C++ - in C++ you have no garbage collection, but you do have control over when (and where) objects are created and destroyed. Object pools in C++ usually work quite differently and are used for different reasons.

If you are okay with doing something that is totally sub-optimal in C++, but matching the patterns and semantics you'd use in a managed language, you can do it with smart pointers - specifically shared_ptr, which is a reference-counted pointer to an object that can be copied around like a regular pointer, only when the last shared_ptr is destroyed, the object is destroyed as well. Just bear in mind that this isn't optimal - using shared_ptr for everything adds overhead in a number of different ways. In general, you may find that if you try to write C++ the way you'd write code in a managed language, the C++ will actually be slower than the same code in a managed language. If you want to write code the way you'd write it in a managed language, just use a managed language. :)

In C++, you're going to have to get used to thinking about ownership semantics. If you want to do something more optimal and more idiomatic, here is what you might do:
- allocate your pool objects up front in a contiguous block or container - you were on the right track with your original code here. The pool should actually own the objects' memory and be responsible for allocating it and releasing it.
- have some way of determining which objects are currently in use. This can be as simple as a flag on each object, or something more complicated like a "free list."
- give your pool "allocate" and "release" functions:
* "allocate" should look at the pool and find the next object that isn't in use, construct it, mark it as in use, and return a pointer to the object.
* "release" should just take a pointer to the object, destroy it, and mark it as no longer in use.
- users of the pool should never take ownership of the objects' memory! That is the pool's job.

In other news, the Flash tutorial is throwing an exception when the pool is exhausted. You appear to be just writing an error message. That's not even close to being the same thing. C++ does have exceptions if you want to use them. Finally, the tutorial code itself has the (rather serious) bug ApochPiQ pointed out, so I'm not sure this is the best tutorial to be learning from.


#5299677 Does Object Pooling with a Vector in C++ have problems with memory?

Posted by Oberon_Command on 07 July 2016 - 02:43 PM

The problem is though does the push_back() and erase() cause memory problems?


Yes, it would, with the way you have things here. If you're passing around pointers to things in a contiguous container like std::vector, performing an operation that causes the container's memory to be reallocated will make those pointers point at garbage, potentially crashing your program. Therefore, you either need to enforce that the pool never changes size (as you're doing here), use a raw array, or use handles instead of pointers.
 

BulletPool(Bullet, int num)


BulletPool's constructor takes a Bullet, and then does nothing with it? What was the intent here?
 

Bullet GetBullet() // get bullet from the pool


GetBullet() returns a Bullet by value - it copies the bullet. If you want GetBullet to return a pointer to the bullet (which I'm guessing is your intent here), then you need to actually do that:
 
Bullet* GetBullet()
{
//...
}
This pool class looks very Java-esque to me - it seems to be assuming that class types are all reference types. You code posted in the OP seems to have the same assumption. Remember that in C++ you must explicitly make something a pointer or a reference if you want reference semantics.
 

else
{
    std::cout << "Error: You exhausted the pool!" << '\n';
}
 
return mBullets[mCounter];


This seems smelly. In the event of the pool being exhausted, you're just giving the caller the last bullet that was allocated. That could cause all kinds of problems - what happens when all the bullets are freed? I would either return nullptr or throw an exception (or use double-indirection as Khatharr did).


#5299661 sort list

Posted by Oberon_Command on 07 July 2016 - 12:55 PM

No, std::sort requires random access iterators. std::list only provides bidirectional iterators, which means you can't use them with std::sort. Use std::list::sort instead.

 
*facepalm* - Mea culpa.
I almost always use std::vector - I forgot about the iterator requirements.


Likewise. std::list is not something I see often, and for pretty good reason. I would be curious to know why OP is using std::lists here.


#5299635 sort list

Posted by Oberon_Command on 07 July 2016 - 11:07 AM

Have you tried std::sort?
 
std::sort(
   std::begin(Ausfalllinie[x]),
   std::end(Ausfalllinie[x]),
   [](const Ausfaelle& a, const Ausfaelle& b)
   {
       return a.color < b.color;
   });
edit: Ninja'd.


#5299398 Intro to Game Programming With DirectX 11 Effects library

Posted by Oberon_Command on 06 July 2016 - 04:47 PM

I'm not familiar with this book, but I can see a few problems straight away:
- LNK2038 indicates that effects11.lib was compiled with a different version of the compiler than the rest of your code.
- LNK2019 indicates that you aren't linking to one of the actual Direct3D libraries.

So: make sure you're linking to all the libraries you need, and make sure you have a version of effects11.lib that's built with VS 2013 (_MSC_VER=1800), since the one you have was compiled with Visual Studio 2010 (_MSC_VER=1600). You may need to compile the library yourself from source. I believe you can find the source code and updated binaries somewhere on this page.


#5298237 Have I been aged out of the industry? And where else can I go?

Posted by Oberon_Command on 27 June 2016 - 08:47 AM

This is the only part of that paragraph that makes sense - people seeing something in me that doesn't actually exist. I haven't had a clue what it was until recently, and I can still be sold on alternatives despite my recent discovery.


My point with that was actually that you were seeing things in others that isn't there, but sure, you might have resting bitch-face, too. I believe it has been shown that people with depression or anxiety problems tend to perceive neutral expressions as negative and positive expressions as neutral.
 

My hygiene and grooming is rigorous, while plain - designed to fade into the scenery. I dress reasonably casual - no different than what you'd see programmers wear at the office. No worse than what others wear at the supermarket, and better than some.


This strengthens the off-putting body language hypothesis. I once again suggest talking to someone about all this and asking questions.
 

I am not about to risk my neck for your little experiment. When we can gamble your life to prove your point, send me an e-mail.


Are you saying that you actually believe that hanging out in any random coffeeshop is risking your life? I need to know what city you live in so I can never go there.
 

Also, I observe humanity a lot - I have to see trouble coming from a mile away to make sure I can deal with them with the few resources I have. Do you know what I see? I see Pulse Shootings and campus pepper-sprayings and church bombings. I see Trayvon Martin and Brandon Teena and Matthew Shepard and know for a fact that I am one butterfly-wing-flap away from suffering the same fate. I know what people are capable of - and don't me garbage about these events are "outliers" or some other story - this happens too often even if those were the only events of their kind.


Watching the news does not count as "observing humanity." The media profits more from bad news than good news, so they don't show all the nice things that happen in the world - mostly just the bad stuff, because that's what grabs people's attention. This is yet another suggestion to me that you need to leave your bubble and actually see how real human beings (as opposed to media caricatures) interact with one another. And yes, those people and events ARE outliers, and pointing that out isn't "garbage." You're treating outliers as the norm. That's fallacious thinking and wrong. Just because bad things happen doesn't mean that the world is shit. Claiming that you are "one butterfly wing away" from something terrible is not a fact, it is total hyperbole at best and complete bullshit at worst. If you live in the US, your chances of being caught up in a terrorist act are less than being struck by lightning!

Everything I'm seeing here suggests to me that:
1. your lack of social experience has caused you to retain mannerisms that are off-putting to others.
2. you have some kind of anxiety disorder (probably as a result of your past) and it's warping your understanding of reality.

Both of these problems are fixable. I know 41 years of experience tell you otherwise, but you don't have to go through life surrounded by enemies. Please, for your own sake, seek help.


#5298169 Have I been aged out of the industry? And where else can I go?

Posted by Oberon_Command on 26 June 2016 - 07:49 PM

As to other times, I avoid people at all costs - the dirty looks at the supermarket (despite taking great pains to be polite) are enough to remind me that the hate is still there.


If you're really, truly getting hateful looks, I again suggest that some aspect of your self-presentation is to blame. Or possibly nothing is actually wrong, the hateful looks are all in your head, and you have a perception of yourself and the world that has been warped away from reality by the very negative experiences you've had, causing you to see hate where only neutrality exists. Bear in mind that "resting bitch-face" is a thing, so even your average human will sometimes see negativity where none actually exists!

How do you usually dress when you visit the supermarket? Do you often leave the house without taking care of personal grooming and hygene? How much thought have you given to precisely why you're getting all this negative attention? You come across as having not given this much thought beyond "people hate me for some reason."

You see yourself as "The Other;" what is the source of that Otherness?
 

The only reason this doesn't make any sense to you is because you still cling to the idea that human begins default to "good". Human being are hairless chimpanzees whoa re one trigger away from an incoherent rage. Surrender all your good thoughts of humanity and it will make perfect sense.


As someone who used to believe the same thing - this viewpoint is both not accurate and extremely unhealthy. Human beings default to "neutral." The vast majority of human beings are not "one trigger away from incoherent rage." Most human beings (children and teenagers notwithstanding) feel empathy towards other humans and feel an innate aversion to the sight of others suffering. That's not to say that folks who are easily enraged don't exist, but they are far less common than you're making it out to be.
 

Also, you've now "talked" to me far more than most people, which means that we're well past the point the effect would remain. You are now immune to whatever ails me - you will never feel the effect directly again.


1. That's not how this works. People who are creepy are generally always creepy. I felt no "effect" upon viewing this thread. If anything, I saw someone in pain and wanted to help them.
2. If this little conversation is more than you get from most people, then I suspect part of your problem is that you don't talk to enough people to have your negative illusions dispelled. If you wallow in self-pity and disillusionment you're never going to see anything that contradicts your negative viewpoint of humanity. If you've been that isolated since your teenage years, that would explain why you apparently think everyone acts like asshole teenagers.

When you do have income again, I strongly suggest looking into therapy, because you seem like you are in a lot of emotional pain and it looks to me like a lot of it is self-inflicted. In the meantime, I have an assignment for you, since you have some spare time - go to a busy coffee shop. Bring a book. Order a coffee. Find yourself a nice chair, and sit there for an hour, discreetly (don't stare at people!) paying attention to your environment. Use the book to hide the fact that you're actually looking around. Watch how human beings interact with one another, and provided you haven't chosen a coffeeshop that is in an utter shithole part of town, I have faith that you'll see no hair-line triggers and no bestial squabbling. Pay attention to their body language and compare it with your own - people without much social experience tend to have odd, off-putting body language. Everything you've said so far has strengthened the off-putting body language/presentation hypothesis.
 

When this thread is finished, can I request it be deleted? I don't want future employers using this as ammunition.


I don't think your employers will be able to find this unless you explicitly and publically provided a link between your GDnet account name and your real name or contact details.


#5298149 Have I been aged out of the industry? And where else can I go?

Posted by Oberon_Command on 26 June 2016 - 03:59 PM

 

Have you ever actually asked one of your friends why they were afraid of you at first?


The friends I have now weren't afraid, couldn't see what others fear - when they see other people react that way (which is rare when they're around) they perceive it as something wrong with them.
 

To clarify, the second request I made earlier in the thread was for you to provide specific anecdotes of the ways that people have responded to you. Again - understand if you aren't comfortable with telling those sorts of stories on a forum, but telling us (eg) exactly what happened when a person "betrayed" you, or the chain of events that led someone to beat you up, might go a long way to helping us understand you.


One specific tale of betrayal:
 
    In seventh grade, I was a poor person attending a junior high school in a very well-to-do, conservative part of town. I was teased and bullied constantly. A few months in, one person who was in my gym class offered to be my friend. Of course, I accepted. The first time we walked home from school together, he led me into an ambush where a he and a handful of his real friends beat me with an inch of my life.
 
I never trusted anyone else ever again.

 

 
I wouldn't exactly be expecting juvenile shit like that to be still happening to you at 41. I wouldn't be expecting stuff like that to happen to you at 21, for that matter! I'm not a therapist, but just given what you've said, I also suggest that it may be worth looking at your own conditioned responses to others and evaluating, from "first principles," whether they still actually make sense. It's hard to trust people when you feel so betrayed, especially when people have treated you so badly, but things do change. Do you have an example of something more recent, perhaps something that happened at work?
 
I also got a bit of the bullying stuff, myself. Among other things, when I was in 8th grade, a group of people I wanted to be friends with tricked me into making out with a shoe during a truth or dare game. This was back when I was awkward, had poor body language, and had been mistaken for autistic a few times, so naturally I didn't gel well with others. I had trust issues, especially with women (since a group of girls had masterminded the trick), for years afterwards. The thing was, by the time I'd hit 12th grade, my trust issues were largely unnecessary, because I was no longer at the mercy of 13 year olds who hated outsiders. I'm now 26 and while I don't actually like anyone who was involved with that, I don't hold any grudges against them.

 

I also don't presuppose that anyone in my professional or personal life is going to act that way, ever, because I'm not in high school anymore and I purposefully surround myself with good people. I don't hold the actions of a bunch of assholes from 13 years ago against all of humanity. They were assholes, and they made the choice to be assholes, which not everyone will. The whole is not responsible for the actions of individuals.  If you were beaten up I realize that it's harder to trust people, but... if you're 41 now, and this happened when you were in 7th grade, you were what, 12? So, unless there's something you aren't telling us, you're letting events from almost 30 years ago rule the way you deal with other human beings. That seems really, really unhealthy.




#5298125 Have I been aged out of the industry? And where else can I go?

Posted by Oberon_Command on 26 June 2016 - 12:03 PM

conq: My feelings are not as extreme as what you imply at the end of your post. Once people get over their initial fear, they tend to find I'm a nice, witty guy. At least, that's what my friends say - their opinion might be biased ;) Nobody "knew something about [me] that even didn't know" (but to be fair, I've heard some surveillance horror stories...) or is trying to get me fired, but people have beaten me up, and people have betrayed me - I don't see why this necessarily means I'm mentally ill.


Far and away from mental illness, to me it sounds like there's something in your mannerisms that creeps people out and you've internalized the reactions you're getting to that. Body language matters, and even little things that are "off" can make people dislike you. Certainly I've had that "fear reaction" to people with body language that was "off" before. I'm self-aware enough to repress it as soon as it happens, but I get the sense that most other people aren't. The good news is that if your body language is your problem, once you're aware of what mannerisms those are, you can change them. It may even be something really simple that you can fix just by paying a little more attention to body language in general. Have you ever actually asked one of your friends why they were afraid of you at first? Or are you just going off guesswork here? I suggest that it's worth finding someone in your personal life who initially had that fear reaction to you and asking them some questions. Your friends are supposed to help you grow, and a real friend will be honest with you if you ask them and make it clear that you're asking because you want to better yourself and not because you want to have your ego stroked.
 
A coworker once told me of interviewing someone who was qualified according to his resume, but had a creepy stare. The candidate would look at you without ever seeming to blink, without ever seeming to look away, which coupled with generally terse answers to questions made him come across as off-puttingly intense. My coworker called it a "serial killer stare." I don't remember whether or not they hired him, off the top of my head. I've encountered people who stare like that, myself, and it really is off-putting. Some more examples of people I've found off-putting:

- someone who had a creepy way of moving his hands

- someone WHOSE VOICE HAD NO VOLUME CONTROL MEANING YOU COULDN'T HOLD ANYTHING RESEMBLING A PRIVATE CONVERSATION WITH HIM

- a number of people who chewed noisily and with their mouth open (yuck!)

- people who smelled bad

- people who stood too close to me

 

These were all things that weren't quite egregious enough to say anything about, but were still sufficiently off-putting to make me (and others) avoid them, at least until I recognized what was happening.
 
I myself used to be someone who could get weird responses from people, and so I have a pretty good idea of how it feels to be on the receiving end of that fear response. Encountering others who triggered that response in me helped me become more aware of my own body language (and in fact that body language was the problem!) and tailor it to match what people were more comfortable with. Eventually the changes became habit and I don't have to think about body language that much anymore.
 
 
To clarify, the second request I made earlier in the thread was for you to provide specific anecdotes of the ways that people have responded to you. Again - understand if you aren't comfortable with telling those sorts of stories on a forum, but telling us (eg) exactly what happened when a person "betrayed" you, or the chain of events that led someone to beat you up, might go a long way to helping us understand you.




#5297993 Have I been aged out of the industry? And where else can I go?

Posted by Oberon_Command on 25 June 2016 - 08:53 AM

I have become jaded thanks to a lifetime of predators attacking me since toddlerhood, and what few people I thought were my allies turn traitor at the most damning opportunity.

I program because it is the strongest skill I know, and the only skill in demand enough where someone might overlook their hatred of the other enough to hire me. But even that is coming to a close - people have grown to hate the other so much I have become unemployable.


You keep bringing this up without elaborating. You seem very insecure about something and I understand how that feels, but we might be able to give you advice more tailored to your situation if you went into more detail about why you think people hate you and don't want to work with you. If you don't feel comfortable doing that, maybe you could give us some examples of the shit that's happened to you so we understand your jadedness?


#5297726 Is there any reason to prefer procedural programming over OOP

Posted by Oberon_Command on 23 June 2016 - 12:14 PM

Just for kicks, take a look how much inheritance or polymorhism is used in the C++ standard library.


Not that I disagree with your general point, but I don't know that I would necessarily call the standard library especially object-oriented - in fact, its original designer believes that the C++ standard library (or at least its predecessor) isn't even object-oriented at all, so I would say that the standard library is not really a useful example of "modern OO". Relevant quotation from that link:
 

Yes. STL is not object oriented... I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work.


Note that he's specifically against runtime polymorphism switched on single interface. Most of what he's talking about specifically refers to OOP as pushed in statically-typed Java-like languages as opposed to languages like SmallTalk.

Of course, this topic has been discussed for a while and nobody agrees on what OO is, so I suggest that OP ought to have specifically referenced "which" OOP we're to compare with procedural programming.


#5297101 Why didn't somebody tell me?

Posted by Oberon_Command on 17 June 2016 - 11:52 PM

C++ doesn't allow function-local classes with static members or template member functions.

I'm a little worried that anyone ever tried to do that...


It doesn't come up all that often, but I saw a case recently where it would have been useful. Briefly: classes that inherited from a particular base class were most concisely implemented with a templated method that was called from within the base class - which was itself a template, and the derived classes were also intended to be passed to another templated method on a different class. The class didn't HAVE to be function local, and the method didn't HAVE to be a template - it just made the code substantially easier to follow, for the same reason that a lambda can make code easier to follow. In fact, in a dynamic-typed language the whole thing possibly could have been replaced with a lambda.




PARTNERS