• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

987 Good

About Zao

  • Rank

Personal Information


  • Twitter
  • Github
  • Twitch
  • Steam
  1. C++ thread problem

    The reason behind @RPTD 's answer is that std::thread copies (or moves) the arguments before calling the function. std::ref (and std::cref) gets you a copyable wrapper around a reference, which is the blessed way of passing a reference for the args of std::thread, please see the Notes at cppreference. Please note that join() on a thread is blocking until the thread completes, so your loop in main will never be reached as the thread in its current state never has a reason to return.
  2. getaddrinfo() trouble

    See the struct definition at https://msdn.microsoft.com/en-us/library/windows/desktop/ms737530(v=vs.85).aspx typedef struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; size_t ai_addrlen; char *ai_canonname; struct sockaddr *ai_addr; struct addrinfo *ai_next; } ADDRINFOA, *PADDRINFOA; You're reinterpreting the start of this struct as an sockaddr, which is completely wrong. You probably want to use the ai_addr field of your addrinfo, which holds the sockaddr instead of a bunch of assorted fields.
  3. DX11 DXGI swapchain call to action

    I don't like the tone of the article that only the newest Windows versions matter at all, only briefly touching on in which Windows version things appeared, not mentioning OS support at all in the "should I do this?" bit. But I guess that's the Microsoft way, forget the past and targetting down-level systems.
  4. In this context, "relative to" means that the space it transforms from is the one mentioned, the space of the node's parent. For the root node, that is the object space. For a child node, it's the space of the parent. It's a bit unfortunate, but the "to" in this usage isn't a direction like in "from/to".
  5. The letter/digit keys have no constants because their value are the ASCII values, so you can just use a character literal 'A' etc.
  6. How to have tamplates that only takes int[] ?

    template <size_t N> void f(int (&arr)[N]) { std::cout << N << std::endl; } For taking arbitrary array types, make the int a template parameter as well.
  7. In general, newer compilers have better conformance to standards, only straying if the functionality is part of a vendor extension or a long-standing defect with the compiler. Ill-formed or non-standard code will only become less and less supported, so you don't have much choice than to update your understanding of the language if you wish to move away from ancient toolchains and their quirks.
  8. C++ Overloading Question

    The authors may have some more or less rational arguments against overloading. In this particular case, the call site may be a bit unexpected if you use NULL or 0 as a null pointer constant, as the integer overload will be chosen. There's nothing intrinsically wrong with overloading, but it can be a bit more clear at the call site what function is intended and what it does. Use common sense and adhere to local style.
  9. OpenGL OpenGL legacy to shader mapping

    The only well-defined standard location is 0 for the vertex position attribute. The use of location 2 for normals and similarly for other attributes is a NVIDIA-specific thing, and will most probably break you hard on other vendors. Please see this discussion on SO: https://stackoverflow.com/a/528824/87969 If you only care about those devices and are happy to rely on vendor-specific behaviour, the mapping should then be that gl_MultiTexCoord0 is at location 8, according to the docs.
  10. Normal question

    When showing source code in public, it may be beneficial to ensure that your indentation is consistent. You seem to have a wild mixture of four spaces and four-wide tabs that expand very poorly in a eight-wide tab world. You may want to invest in a source code formatter or an IDE that unscrews your indentation.
  11. Particle system

    You're picking the X, Y, and Z components from different unrelated positions as each call to GenSpherePointCorrect makes a completely new position. You need to generate a single Vector3 each loop iteration and assign its components to the vertex position.
  12. As this is the primary web search hit for the subject, any non-zero flags like the read-only depth/stencil ones in a DSV desc require feature level 11_0 or greater, the debug runtime returns invalid arg and issues a diagnostic: D3D11 ERROR: ID3D11Device::CreateDepthStencilView: A non-zero Flags field (0x1) is not valid, unless the GetFeatureLevel returns D3D_FEATURE_LEVEL_11_0 or greater. [ STATE_CREATION ERROR #2097153: CREATEDEPTHSTENCILVIEW_INVALIDFLAGS] D3D11 ERROR: ID3D11Device::CreateDepthStencilView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #148: CREATEDEPTHSTENCILVIEW_INVALIDARG_RETURN]
  13. Constructs like the one in fragment #4 is often erroneous even if you check both flags. eof() will not be true until a read attempt is made across the end of the file.   Unless there is additional checking below the std::getline call, it will run one final failing time after all the data is consumed and the code below may expect the string to contain valid data. Instead the code ought to inspect the state of the stream after a read operation. Typically you would design a "read all the lines" loop like: while (std::getline(is, str)) { ... }
  • Advertisement