C++

Programming/C++ & Unreal

vprintf, vsprintf 등 가변 인자 함수를 활용한 로그 함수 개발 시에 포맷 warning 출력하기

printf C++에서 printf 사용시에 format을 잘못 지정하였다면 이렇게 컴파일러단에서 C4477 C4313 C6067 의 워링 에러가 발생하여 잘못된 포맷으로 인한 오류나 크래시를 방지 할 수 있다. vprintf, vsprintf... 하지만 보통 printf를 저렇게 사용하는 일은 거의 없다. 아래와 같이 보통 로그를 남기는 함수를 va_list를 사용하여 커스터마이징하곤 한다. (UE_LOG도..) 하지만 이렇게 사용하면 포맷 관련 warning이 발생하지 않아서 실수를 저지르기가 너무 쉽다. 해결법 MSVS에서는 저런 사용자 함수에서 포맷 체크를 하는 방법이 없어서 이렇게 편법으로 Debug 빌드 시에만 printf로 체크하는 방식이 가능하다. sizeof() 안에 있는 printf구..

Programming/C++ & Unreal

StackWalk64가 context에 의하여 Access violation를 유발

#include #include #include BOOL InitSymHandler(HANDLE hProcess) { if (SymInitialize(hProcess, NULL, TRUE)) { SymSetOptions(SYMOPT_LOAD_LINES); return TRUE; } return FALSE; } LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exceptionInfo) { CONTEXT* context = exceptionInfo->ContextRecord; STACKFRAME64 stackFrame; memset(&stackFrame, 0, sizeof(STACKFRAME64)); stackFrame.AddrPC.Mode = Addr..

Programming/C++ & Unreal

C++ 가변인자(va_list)를 오버로딩 하지 말자.

#include #include void Print(const char* format, va_list args) { // 2번째 Print 함수에서 호출함 vprintf(format, args); } void Print(const char* format, ...) { // main 에서 호출함 va_list args; va_start(args, format); Print(format, args); va_end(args); } int main() { char a[] = "Hello "; char b[] = "world!"; Print("%s %s", a, b); // "Hello world!" 출력됨. return 0; } 위 코드는 아무 문제가 없다. 가변인자가 잘 들어가서 2번째 Print 함수 -> ..

Programming/C++ & Unreal

C++ parallel for_each (thread) exception

#include #include #include #include #include #include LONG WINAPI UnhandleExceptionHandler(_EXCEPTION_POINTERS* exceptionInfo) { std::cout

Programming/C++ & Unreal

C++ config parser

텍스트를 파싱하는 로직이 필요해서 간단히 작성한 프로그램. 긴 설명은 필요없을 것 같아 소스만 남김! 사용법 #include #include "ConfigParser.h" int main() { CConfigParser test("test.ini"); if (test.IsSuccess()) { std::cout

Programming/C++ & Unreal

언리얼 플레이어 회전값 직접 바꾸기

UGameplayStatics::GetPlayerController(this, 0)->SetControlRotation(rideTarget->GetComponentRotation()); RideTarget의 로테이션에 플레이어 컨트롤러 화면을 바꾸는 건 이렇게 하면됨. 언리얼 인풋 컴포넌트에서 조정해서 그럼.

Programming/C++ & Unreal

언리얼 C++에서 경로로 에셋 불러오기.

LoadObject는 로드되지 않은 오브젝트를 레퍼런싱할때,FindObject는 이미 로드된 오브젝트를 레퍼런싱할때 쓰라고함. GridTexture = LoadObject(NULL, TEXT("/Engine/EngineMaterials/DefaultWhiteGrid.DefaultWhiteGrid"), NULL, LOAD_None, NULL); 이런식으로 하면되는듯 /Game/Sprite/Crosshair/Item_Sprite 경로는 대충이럼.Game = Content라고 생각하면될듯 const ConstructorHelpers::FObjectFinderSM_Body(TEXT("/Game/P38/SM_P38Body.SM_P38Body"));이런식으로 할수도있뜸 경로는 콘텐츠 브라우저에서 레퍼런스 복사를 하..

Programming/C++ & Unreal

UPaperSpriteComponent 쓰기

그냥 UPaperSpriteComponent를 쓰려면 에러가 잔뜩 난다..뭔가 하고 거의 반나절을 찾아본결과..PaperSpriteComponent.h를 인클루드하고,빌드.cs에, Paper2D를 추가하면된다.네트워크등 다른것들도 이런식으로 모듈확장을 해야하는덧.

Programming/C++ & Unreal

언리얼 C++ Enum 블루프린트에서 쓰기

UENUM(BlueprintType) enum class ECrossHair : uint8 { CROSSHAIR_NoDetect UMETA(DisplayName="NoDetect"), CROSSHAIR_Item UMETA(DisplayName="Item"), CROSSHAIR_Ride UMETA(DisplayName="Ride") }; 이런식으로 클래스 헤더 위에서 선언하고 쓰면됨.

Programming/C++ & Unreal

언리얼 4.12 Visual studio 2015 Update 3 사용하기

command line argument number 261 does not match precompiled header가 뜬다면 https://forums.unrealengine.com/showthread.php?115833-Tutorial-Fix-for-the-Visual-Studio-Update-3-without-Source-Control 여기 따라하면됨!!!!!

장형이
'C++' 태그의 글 목록