Debugging app with CImg library included - c++

I'm writing program to analyze 3D raw images. I have strange problem with loading this files. During debugging:
(...)
string input_filename = file_i;
CImg<unsigned char> img_org(500, 500, 500, 1);
img_org.load_raw(file_i, 500, 500, 500, 1);
(...)
I have IO Exception, looks like:
What is more, after compile, program works ok. It's important for me to debug entire program, because I must look into further functions.

Ok, I've found out that debugger is looking for my .raw file in different folder. It was silly question, but already I have the answer.

Related

SDL_Image loading a png returns nullptr

Alright so I'm trying to make a game engine for myself, and I've decided that it would be best to start loading images as files other than bitmaps using the SDL Image library. I've set up the library correctly according to conversations online, include set up and linker set up, and yet when I try to load a file that does indeed exist it just returns an empty surface.
Heres the code loading the file...
SDL_Surface* background = IMG_Load("Assets/bg.png");
background = SDL_ConvertSurface(background, mtrx->format, 0);
if (!background) {
ofstream file("text.txt");
file << IMG_GetError() << endl;
file.close();
}
...And the error I get in "text.txt"...
Parameter 'surface' is invalid
At the beginning of the script I have included SDL.h, then SDL_image.h, and the window initiation has IMG_Init(IMG_INIT_PNG) after SDL_Init. Visual studio shows no errors whatsoever, and everything BUT IMG_Load works fine.
All help would be appreciated, and I can provide any other code that might be helpful!

Application error despite console displaying no errors?

I’ve been watching this tutorial and I’ve run into an error. For some reason even though I fixed the unresolved external symbols errors, the application error is still available. https://imgur.com/a/ppngHxL I don't know whether it's due to my computer because it says it's a 64 bit processing system, but nothing seems to work.
I tried using one tutorial in that I extract the sdl2.dll file then copy pasting it into the windows32 file, and that still didn't work, and the properties panels don't have a compatibility tab on my computer. I'm not sure what to try next. Here's the code
#include "SDL.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window = SDL_CreateWindow("title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 400, SDL_WINDOW_SHOWN );
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(3000);
return 0;
}
The application does not start properly (0xc000007b)
The root cause is the lack of the required DLL, and the wrong version of the dll is also a possible reason, the report error of the two are exactly the same.
I noticed the following question. Is it possible that different versions caused your problem. But I tested and found nothing, it work.
Have you performed this step? Copy SDL2.dll to the root directory of your project. This may also cause some problems, although the compilation is successful.
Of course, it is more likely that you are missing other system files or dlls. It is not easy to guess which file missing. If this is the case, I am sorry that I have no better suggestions.

How to apply image effects to a JPEG in a memory buffer using LEADTOOLS 19

I'm making a Windows executable using C++, LEADTOOLS19, and VS2015 to read an image from a server, apply an image effect to it using LEADTOOLS, and display it in a browser.
The server provides me the image as an array of chars containing the JPEG encoding of the image (starting with "ÿØÿà") and the length of this buffer. Most of the LEADTOOLS functions read images from files, but I don't want to have to write it to disk just to read it as a bitmap.
The first thing I tried was the StartFeedLoad function:
//pImageData is the buffer of JPEG data, and imageLength is the
//server-provided size of pImageData in bytes
LBuffer buf((L_VOID *)pImageData, imageLength);
LFile imgFile;
LBitmap bitmap;
imgFile.SetBitmap(&imgbitmap);
// Initialize the file-load process
imgmemfile.StartFeedLoad(8, 0,
LOADFILE_ALLOCATE | LOADFILE_STORE, NULL);
imgmemfile.FeedLoad(&buf);
imgmemfile.StopFeedLoad();
With this code, I get this exception when trying to run StartFeedLoad:
Exception thrown at 0x000007F855BC2662 (ltwvcax.dll) in getimage.exe:
0xC0000005: Access violation reading location 0x0000000000000148.
I tried a few different things before calling StartFeedLoad, and tried changing the parameters I was passing it, but got that exception every time.
With that not working, the next method I tried was to save the buffer as an in-memory file using the LEADTOOLS library LMemoryFile class:
LBuffer buf((L_VOID *)pImageData, imageLength);
LMemoryFile imgmemfile;
BITMAPHANDLE pbit;
//The bitmap the image will be loaded into
LBitmap bitmap;
imgmemfile.SetBitmap(&bitmap);
//Load the buffer to the image
ret = imgmemfile.LoadMemory(buf, 0, ORDER_RGBORGRAY, LOADFILE_ALLOCATE | LOADFILE_STORE, NULL);
At this point, LoadMemory returns WRPERR_INVALID_PARAMETERS: One or more invalid parameters were specified. I've tried different bitsPerPixel values, color orders, and with or without adding another NULL parameter as fileInfo but still get the same error.
I feel like I need to do something else to "prep" the bitmap to load, but I don't know it's size or anything else to initialize it.
Thanks!
EDIT 5/9/16: Added "GetInfo" as indicated by Leadtools:
//Load image
LBuffer buf((L_VOID *)pImageData, imageLength);
//LFile imgmemfile;
FILEINFO fileInfo = FILEINFO();
LMemoryFile imgmemfile;
BITMAPHANDLE pbit;
if (LBase::GetLoadedLibraries() & LT_FIL == 0)
return false;
LBitmap bitmap;
imgmemfile.SetBitmap(&bitmap);
ret = imgmemfile.GetInfo(buf, &fileInfo, sizeof(FILEINFO), 0, NULL);
ret = imgmemfile.LoadMemory(buf, 0, ORDER_RGBORGRAY, LOADFILE_ALLOCATE | LOADFILE_STORE, NULL, &fileInfo);
ret = imgmemfile.Save(&buf, FILE_JPEG, 8, 30, NULL);
The code gets past the additional library check, but GetInfo returns -2041, indicating that LTFIL isn't loaded.
You should use LMemoryFile::GetInfo and LMemoryFile::LoadMemory if you have the whole file in memory at the start. If you don't, then FeedLoad is the way to go. There is an example here: https://www.leadtools.com/help/leadtools/v19/main/clib/lfile__startfeedload.html
You can find a full working example in your LEADTOOLS installation folder: C:\LEADTOOLS 19\Examples\ClassLibrary\MSVC\FeedLoad
The functions that LEADTOOLS Support gave me were correct, but I was still ahving the issue because I was linking to both the Unicode and ANSI versions of the Leadtools C++ class library (Ltwvc_x.lib AND Ltwvc_ax.lib). When I removed the Unicode library (from my ANSI project) everything worked fine.

Unreal Engine 4: save rendered frame to memory

Previously, I was looking to output frames rendered by UE4 to file.
I managed to do this and the details can be found in this StackOverflow post
The function to out put the frame to file is:
FScreenshotRequest::RequestScreenshot(filename, false, false);
Now, instead of writing to file, I would like to write to memory. I don't want to write to file and then read into memory.
I have been digging through the source code and found where screenshots are being made, but am having some trouble.
ViewportClient->ProcessScreenShots(this); is being called on line 1012 of UnrealClient.cpp
Following that, I found that the screenshot is actually being generated here:
bScreenshotSuccessful = GetViewportScreenShot(InViewport, Bitmap);
So, after finding all the bits that I think I need, I tried to recreate it in a custom Actor:
UGameViewportClient* gameViewport = GEngine->GameViewport;
FViewport* InViewport = gameViewport->Viewport;
TArray<FColor> Bitmap;
bool bScreenshotSuccessful = GetViewportScreenShot(InViewport, Bitmap);
if (bScreenshotSuccessful){
FIntVector Size(InViewport->GetSizeXY().X, InViewport->GetSizeXY().Y, 0);
TArray<uint8> CompressedBitmap;
FString ScreenShotName = TEXT("out.png");
FImageUtils::CompressImageArray(Size.X, Size.Y, Bitmap, CompressedBitmap);
FFileHelper::SaveArrayToFile(CompressedBitmap, *ScreenShotName);
}
For some reason, bool bScreenshotSuccessful = GetViewportScreenShot(InViewport, Bitmap); throws an Access violation reading location 0x0000000000000020. exception.
I think the error has something to do with this line:
Viewport->ReadPixels(Bitmap, FReadSurfaceDataFlags(), ViewRect)
I've treid 'googeling' for what an 'Access violation' is, and it seems it is something to do with a null pointer or something like that, but I am still not able to figure this out as I'm rather new to c++.
Question
How can I fix this so that bScreenshotSuccessful is true?
NOTE: I realise that FFileHelper::SaveArrayToFile(CompressedBitmap, *ScreenShotName); attempts to save to file, despite me saying that is not what I want to do, so please ignore that as if I have the bitmap, I can compress and stream it.
You have ViewRect just of three points instead of four and in wrong format. Try this snippet:
FIntRect Rect(0, 0, InViewport->GetSizeXY().X, InViewport->GetSizeXY().Y);
bScreenshotSuccessful = GetViewportScreenShot(InViewport, Bitmap, Rect);

Playing mp3 files with mciSendString (MCIERR_CANNOT_LOAD_DRIVER)

I am trying to write some code that can play an .mp3 file. I thought I could use the mciSendString call, but I am getting a strange error.
So, when I have this code:
int rc=mciSendString(L"open songname.mp3 alias song1", NULL, 0, 0);
rc returns with the number 266, and the error string returned with GetErrorString was:
"Unknown problem while loading the specified device driver."
Error 266 is MCIERR_CANNOT_LOAD_DRIVER
I have also tried:
int rc=mciSendString(L"open songname.mp3 type mpegvideo alias song1", NULL, 0, 0);
and received the same error.
I thought it may be the mp3 file, but I tried a few different ones and kept getting the same error.
My code is in C++ and is running on Windows 7. Is my code missing something?
Try surrounding songname.mp3 with an extra pair of quotes (be sure to escape them with backslashes).
It looks like I didn't have an mp3 codec for MCI. (Actually answered by #LightnessRacesinOrbit in comments to the question.)