A little bit strange that the function createScreenshot works fine, but the CreateImage or CreateImageFromFata will all leads to same error. (It is hard to say it is an error, the program just crashed)
I tried a lot of times and now I am pretty sure that the program will crash when the functions mentioned before are called.
Did I miss anything or is that a problem in trunk version?
Code: Select all
#include <irrlicht.h>
//#include <SIrrCreationParameters.h>
#include <iostream>
#include <chrono>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace chrono;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
int main(int argc, char* argv[])
{
int widthOfDisplayZone = 800;
int heightOfDisplayZone = 600;
int widthOfSubimage = 20;
int heightOfSubimage = 20;
int widthOfHole = 2;
int heightOfHole = 2;
video::SColor backgroundColor;
video::SColor dotColor;
std::string filename;
bool isTesting = true;
try
{
if (argc == 3 && std::string(argv[1])=="t")
{
isTesting = true;
widthOfDisplayZone = atoi(argv[2]);
}
else if (argc == 2 && atoi(argv[1]) != 0)
{
isTesting = false;
widthOfDisplayZone = atoi(argv[1]);
}
else
{
throw 0;
}
}
catch(int error)
{
cout<<"Usage:\n"<<"'./pattern-irrlicht t HEIGHT' for testing images\n"<<"'./pattern-irrlicht HEIGHT' for images for using\n";
return 0;
}
// Load the width and height.
heightOfDisplayZone = widthOfDisplayZone * 210 / 297;
heightOfDisplayZone = 1024;
widthOfDisplayZone = 1024;
backgroundColor = SColor(255,255,255,255);
dotColor = SColor(255,0,0,0);
IrrlichtDevice *device =
createDevice(
video::EDT_OPENGL,
dimension2d<u32>(widthOfDisplayZone, heightOfDisplayZone),
16,false,true,true,0);
device->setWindowCaption(L"Light field display");
IVideoDriver* videoDriver = device->getVideoDriver();
ISceneManager* sceneManager = device->getSceneManager();
IGUIEnvironment* guiEnvironment = device->getGUIEnvironment();
video::IRenderTarget* simulatorRenderTarget = 0;
video::ITexture* renderTargetTex = 0;
scene::ICameraSceneNode* fixedCam = 0;
renderTargetTex = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "RTT1", video::ECF_A8R8G8B8);
video::ITexture* renderTargetDepth = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "DepthStencil", video::ECF_D24S8);
simulatorRenderTarget = videoDriver->addRenderTarget();
simulatorRenderTarget->setTexture(renderTargetTex, renderTargetDepth);
videoDriver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, backgroundColor);
videoDriver->setRenderTargetEx(simulatorRenderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0));
videoDriver->draw2DRectangle(
dotColor,
core::rect<s32>(0,0,400,400)
);
guiEnvironment->drawAll();
videoDriver->endScene();
filename = "Img-testing-" + to_string(widthOfDisplayZone) + "-" + to_string(heightOfDisplayZone) + ".png";
void* imageData = renderTargetTex->lock();
IImage * image = videoDriver->createImageFromData(renderTargetTex->getColorFormat(), renderTargetTex->getSize(), imageData);
videoDriver->writeImageToFile(image, path(filename.c_str()));
while(device->run());
}
Code: Select all
Irrlicht Engine version 1.9.0
Linux 3.19.0-49-generic #55~14.04.1-Ubuntu SMP Fri Jan 22 11:24:31 UTC 2016 x86_64
Creating X window...
GLX >= 1.3
Visual chosen: : 33
Using renderer: OpenGL 4.5.0
GeForce GTX TITAN/PCIe/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
Dedicated video memory (kB): 6291456
Total video memory (kB): 6291456
Available video memory (kB): 5118500
GLSL version: 4.5
[1] 12468 segmentation fault (core dumped) ./pattern-irrlicht t 1000