## Recommended Posts

this is super strange...

I have this function here:

template<typename TFirst, typename... TArgs>
bool util::LogConsole(const TFirst& first, const TArgs&... rest)
{
std::cout << first << " ";
return LogConsole(rest...);
}

bool util::LogConsole()
{
std::cout << std::endl;
return false;
}

it's recursive, keep printing "first" and recursively sending the rest, until rest is empty and the overload taking no argument is called, which just print a newline. Ignore the bool return.

Anyway, now I have this code somewhere else:

for (auto& E : Entities) {
float valx = E->GetPosition().x;//return 751
float valy = E->GetPosition().y;//return 838
LogConsole(valx, valy);
}

Entities is a vector<unique_ptr<Entity>> which currently only contains the derived from Entity player Paddle, so I access the Base class Entity method called GetPosition, which is the center pivot coordinates of the object.

I pass the variable to LogConsole which predictably prints:

Quote

751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838
751 838

But not I try to call LogConsole without those 2 variables inbetween, like this:

	for (auto& E : Entities)
{
LogConsole(E->GetPosition().x, E->GetPosition().y);
}

and watch what kind of output I get! :

Quote

751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732
751 17168732

... the y value is an unreasonable value o_o

How is this even possible?! Since only the second value is being affected, my assumption is that there is some weird interplay with the second template parameter, the variadic argument...but I wasn't able to debug it even stepping trough it line by line...can anyone come with an explanation for this really strange behaviour?

Edited by MarcusAseth

##### Share on other sites

Here below a main.h with my basic setup , you can run it yourself to see it happening in your console:

#include <iostream>
#include <vector>
#include <memory>
using namespace std;

struct Point {
int x, y;
};

class Entity {
float XCenter,YCenter;
public:
Entity(int x, int y) { XCenter = x; YCenter = y; }
const Point& GetPosition()const { return Point{ static_cast<int>(XCenter),static_cast<int>(YCenter) }; }
};

{
public:
Paddle(int x, int y) :Entity(x, y) {}
};

void LogConsole()
{
std::cout << std::endl;
}

template<typename TFirst, typename... TArgs>
void LogConsole(const TFirst& first, const TArgs&... rest)
{
std::cout << first << " ";
return LogConsole(rest...);
}

int main()
{
vector<unique_ptr<Entity>> Entities;

for (auto& E : Entities)
{
LogConsole(E->GetPosition().x, E->GetPosition().y);
}

return 0;
}

Edited by MarcusAseth

##### Share on other sites

Your variadic template is working fine. The problem is you are returning a reference to a temporary:


vvv ref vvv                              vvv temp vvv
const Point& GetPosition()const { return Point{ /* snip */ }; }

Quote

How is this even possible?! [...] can anyone come with an explanation for this really strange behaviour?

All things are possible for him who readeth from invalid memory. =P

Edited by Servant of the Lord

##### Share on other sites
Spoiler

Thanks @Servant of the Lord , I feel like that one shouldn't have slipped past me, damn...  Probably one more sign that I need to pick up Scott Meyers books as soon as possible

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628373
• Total Posts
2982306
• ### Similar Content

• I am trying to recreate the combat system in the game Life is Feudal but make it more complex. The fighting system works by taking in the direction of the mouse movement and if you press the left click it will swing in that direction, though stab, overhead, left (up, down, left right) and right are the only swings that you can do. If you wanted to you could also hold the swing by holding left click so you are able to swing at the perfect moment in the battle. I want to change this so add in more swing directions but I also want to code this from scratch in Unreal. Can anyone give me any pointers or maybe a few snippets of code that work in Unreal that could help me start to implement this type of system?

• By rXpSwiss
Hello,
I am sending compressed json data from the UE4 client to a C++ server made with boost.
I am using ZLib to compress and decompress all json but it doesn't work. I am now encoding it in base64 to avoid some issues but that doesn't change a thing.
I currently stopped trying to send the data and I am writing it in a file from the client and trying to read the file and decompress on the server side.
When the server is trying to decompress it I get an error from ZLib : zlib error: iostream error
My question is the following : Did anyone manage to compress and decompress data between a UE4 client and a C++ server ?
I cannot really configure anything on the server side (because boost has its ZLib compressor) and I don't know what is wrong with the decompression.
Any idea ?
rXp

• I was wondering if someone could explain this to me
I'm working on using the windows WIC apis to load in textures for DirectX 11. I see that sometimes the WIC Pixel Formats do not directly match a DXGI Format that is used in DirectX. I see that in cases like this the original WIC Pixel Format is converted into a WIC Pixel Format that does directly match a DXGI Format. And doing this conversion is easy, but I do not understand the reason behind 2 of the WIC Pixel Formats that are converted based on Microsoft's guide
I was wondering if someone could tell me why Microsoft's guide on this topic says that GUID_WICPixelFormat40bppCMYKAlpha should be converted into GUID_WICPixelFormat64bppRGBA and why GUID_WICPixelFormat80bppCMYKAlpha should be converted into GUID_WICPixelFormat64bppRGBA
In one case I would think that:
GUID_WICPixelFormat40bppCMYKAlpha would convert to GUID_WICPixelFormat32bppRGBA and that GUID_WICPixelFormat80bppCMYKAlpha would convert to GUID_WICPixelFormat64bppRGBA, because the black channel (k) values would get readded / "swallowed" into into the CMY channels
In the second case I would think that:
GUID_WICPixelFormat40bppCMYKAlpha would convert to GUID_WICPixelFormat64bppRGBA and that GUID_WICPixelFormat80bppCMYKAlpha would convert to GUID_WICPixelFormat128bppRGBA, because the black channel (k) bits would get redistributed amongst the remaining 4 channels (CYMA) and those "new bits" added to those channels would fit in the GUID_WICPixelFormat64bppRGBA and GUID_WICPixelFormat128bppRGBA formats. But also seeing as there is no GUID_WICPixelFormat128bppRGBA format this case is kind of null and void
I basically do not understand why Microsoft says GUID_WICPixelFormat40bppCMYKAlpha and GUID_WICPixelFormat80bppCMYKAlpha should convert to GUID_WICPixelFormat64bppRGBA in the end

• By HD86
As far as I know, the size of XMMATRIX must be 64 bytes, which is way too big to be returned by a function. However, DirectXMath functions do return this struct. I suppose this has something to do with the SIMD optimization. Should I return this huge struct from my own functions or should I pass it by a reference or pointer?
This question will look silly to you if you know how SIMD works, but I don't.

• Hey, Im using directx allocate hierarchy from dx9 to use a skinned mesh system.
one mesh will be only the skeleton with all animations others meshes will be armor, head etc, already skinned with skeleton above. No animation, idle position with skin, thats all I want to use the animation from skeleton to other meshes, so this way I can customize character with different head, armor etc. What I was thinking its copy bone matrices from skeleton mesh to others meshes, but Im a bit confused yet what way I can do this.

Thanks.

• 10
• 9
• 13
• 24
• 11