Jump to content

  • Log In with Google      Sign In   
  • Create Account

Khatharr

Member Since 24 Apr 2010
Offline Last Active Private

#5285507 Data Structures Help!

Posted by Khatharr on 06 April 2016 - 05:33 PM

You can't split up templates like that because of the way they compile.
 
You can either define the functions inline with the declaration or use a .inl file instead of a .cpp file and then include the .inl at the end of the header file.
 
Example of method A:
template <class T>
class Foo {
public:
  Foo(T bar) { //define the function inline
    baz = bar;
  }
private:
  T baz;
};
Example of method B:
//Foo.h

template <class T>
class Foo {
public:
  Foo(T bar);
private:
  T baz;
};

#include "Foo.inl" //include this at the end, not the beginning
//Foo.inl


template<typename T>
Foo<T>::Foo(T bar) {
  baz = bar;
}

ninja'd


#5285115 Help with debugging segfault

Posted by Khatharr on 04 April 2016 - 03:57 PM

Contents of m_gameObjects:

  GameObject* button1 = new MenuButton( new LoaderParams( 100, 100, 400, 100, "playbutton" ), s_menuToPlay );
  GameObject* button2 = new MenuButton( new LoaderParams( 100, 300, 400, 100, "exitbutton" ), s_exitFromMenu );
  
  m_gameObjects.push_back( button1 );
  m_gameObjects.push_back( button2 );

Process of MenuState::update()

void MenuState::update() {
  for( int i = 0; i < m_gameObjects.size(); i++ ) {
    m_gameObjects[i] -> update();
  }
}

So that's going to check them in order, yes?

 

But when you click the first button there you delete the MenuState object. So the loop goes:

 

i = 0

m_gameObjects[0]->update(); //check the s_menuToPlay button - delete the menu state

i = 1

m_gameObjects[1]->update(); //m_gameObjects doesn't exist anymore. segfault

 

-

 

Please get much more cozy with constructors and destructors and try to avoid singletons.

 

Incidentally, you're leaking memory there since you're using new to allocate the buttons and then never deleting them.

 

In theory it could also fail on .size() in the loop header, but we're in undefined behavior land, so anything can happen.

 

There are a few approaches that could clean this up, but the most direct one would be to have an activated button place its callback in an event queue and execute the queue after you're outside of the objects that it may manipulate. If you're around later check in the chat and see if I'm around. We can talk about ctors/dtors and a better memory management strategy for this that may save you some trouble.




#5285112 Community College or Game Development?

Posted by Khatharr on 04 April 2016 - 03:46 PM


wouldn't it be easier to get into this industry with a 100% completed project rather than any kind of degree?

 

How about both?




#5284924 In terms of engine technology, what ground is left to break?

Posted by Khatharr on 03 April 2016 - 04:05 PM

 

Today's engines are built around the ideas from ten years ago. It isn't that they are bad, only that Unreal and Unity feel a little dated compared to new engines being released.

Non-collaborative development for one thing. Game processing is inherently single-threaded or operates as though it were on a single thread. Design of systems in a way that is structured well for object hierarchies, but frequently implemented in ways that are not cache friendly nor parallel friendly. The engines can leverage some of the latest round of rendering technologies, but not all of them.

There is much growth to be had.

 

 

To be fair... game processing is kinda hard to do out of single threads.

 

 

That's what indicates that there's still work to be done. If it were easy to do that would indicate that we've mostly got it licked. When asking, "Where should we grow?" one way of getting good answers is to ask, "What sucks and how can we make it suck less?"

 

Of course then you also have to do the work, and that's not easy itself.

 

Hmm...

 

Maybe we can innovate a way to make innovation easier... :ph34r:




#5284730 Javascript Canvas Question - Confusing coordinates, velocity vectors and the...

Posted by Khatharr on 02 April 2016 - 03:34 AM

You're just looking at the space from the wrong direction.

 

unit-circle9_43217_lg.gif




#5284648 Actor object understanding

Posted by Khatharr on 01 April 2016 - 02:25 PM

The compiler will tell you where the error is coming from. Post the full compiler output, please.

 

(inb4 SOLID explosion)




#5284156 Actor object understanding

Posted by Khatharr on 29 March 2016 - 08:14 PM

I don't always inheritance architecture...

 

...but when I do Actor is an abstract class derived from Entity that serves as the base for the player and NPC types.




#5283980 queue of unique_ptr issue

Posted by Khatharr on 28 March 2016 - 08:50 PM

Not sure if you're responding to the original question or nfries88, Khatharr...


It was like the joke about the plane: it went over your head.

 

------

Edit: Looks like you're not alone in that regard either, given the downvotes.




#5283775 queue of unique_ptr issue

Posted by Khatharr on 27 March 2016 - 05:41 PM

#include <iostream>
#include <memory>

class Foo {
public:
  Foo(int i) : ip(std::make_unique<int>()) {
    *ip = i;
  }

  Foo(Foo&& other) {
    ip = std::move(other.ip);
  }

  void show() const {
    std::cout << *ip << "\n";
  }

private:
  std::unique_ptr<int> ip;
};

void test(Foo obj) {
  obj.show();
}

int main() {
  Foo f(42);
  test(f);
  f.show();
  std::cin.get();
}
main.cpp(28): error C2280: 'Foo::Foo(const Foo &)': attempting to reference a deleted function



#5283470 Regex - Scan a string for special chars

Posted by Khatharr on 25 March 2016 - 04:46 PM

After poking around it doesn't look like there's an umlaut class, but if you're using a locale that supports umlaut (see http://stackoverflow.com/questions/11254232/do-c11-regular-expressions-work-with-utf-8-strings) then you should be able to just manually include them in the regex:

 

std::regex reg("[^A-Za-z0-9äüöÄÜÖ\s]");




#5283281 How can I locate a memory leak?

Posted by Khatharr on 24 March 2016 - 05:52 PM

You really could have ended the discussion on smart pointers there and come off as being reasonable.

 
There's at least three bad assumptions behind that statement.




#5283254 Should I give up?

Posted by Khatharr on 24 March 2016 - 03:19 PM

Just because we program or develop games (or any other type of software) doesn't mean we are an authority on who can and can't develop games.

 
That's right. Ultimately the only authority on whether or not you can be a game developer is me.
 
So stay on your toes and get back to work.

48269.jpg

 

(Truth be told, though... You shouldn't let other people determine your fate for this one simple reason: Everyone wants to control you some degree or another, and the only way to get any kind of entertainment out of life is to frustrate people mercilessly over this.)




#5283235 How can I locate a memory leak?

Posted by Khatharr on 24 March 2016 - 01:48 PM

 


There might even be problems where you honestly cannot apply RAII in a reasonable manner.

The classic example of a problem in which RAII is inappropriate is transactions with commit/rollback semantics.  Otherwise, it is Best Practice™.

 

 

?

 

Don't you just write a 'commit' function on the transaction object that disables the default rollback-on-destruction behavior?

 

Or do you mean something else?




#5283091 How can I locate a memory leak?

Posted by Khatharr on 24 March 2016 - 03:28 AM

Khatharr, your original comment did sort of read like "you should just always use RAII for allocations"

No it doesn't. It reads like this:
 

If you're using VS

https://vld.codeplex.com/

Otherwise valgrind is the only tool I've heard of.

Honestly, if you just learn to use RAII then you don't have to mess with it much anymore.

 
Note that one line of four is about RAII. The others are about leak tools.

 

Further, seeing that RAII will eliminate the overwhelming majority of leaks I'd say that fourth line is a pretty fucking fair.
 

which doesn't apply well to all cases.

Yes it does. But you have this misconception because:
 

I'm guessing you were referring more specifically to the use of smart pointers

No. I'm not.
 

Even this wouldn't catch all memory leaks

 
AGAIN, I NEVER SAID IT WOULD.
 

unique pointers don't work well for all cases and shared pointers have a weakness to circular references (weak pointers can fight circular references, but require that a programmer know where to use them).

Entirely irrelevant.
 

Also in some cases the overhead of smart pointers is unacceptable.

JFC are you even being serious right now? You're being serious, aren't you?

 

Even ignoring the obvious fact that you should still use RAII in cases where the naive application of smart pointers is not appropriate, the overhead from smart pointers is insanely trivial. The only way you can get a performance issue from them is to do something dumb like continually creating and destroying them in large numbers. Even in that case the performance hit from the smart pointers is effectively invisible when held next to the overhead from the repeated allocations and releases that you damn well know you shouldn't be doing in the first place.

 

Using RAII doesn't mean shoehorning everything you see in unique_ptr or shared_ptr and then just shutting off your brain and rolling your face on the keyboard. It means not leaving your resource management solely up to PROVEN SOURCES OF CONTINUAL FAILURE like human memory and myopic analytical capability.

 

STOP WRITING BUGS ON PURPOSE.




#5283032 How can I locate a memory leak?

Posted by Khatharr on 23 March 2016 - 07:09 PM

And the part where nobody said that is clearly not salient.






PARTNERS