Commit cae05e6a authored by hybrid's avatar hybrid

Fix segfaults in case the image is not created. Add test which simply checks...

Fix segfaults in case the image is not created. Add test which simply checks which formats are supported for screenshots.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3752 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 8d6dd909
...@@ -4285,7 +4285,7 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE ...@@ -4285,7 +4285,7 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
break; break;
case ECF_R8G8B8: case ECF_R8G8B8:
fmt = GL_BGR; fmt = GL_BGR;
type = GL_RGB; type = GL_UNSIGNED_BYTE;
break; break;
case ECF_A8R8G8B8: case ECF_A8R8G8B8:
fmt = GL_BGRA; fmt = GL_BGRA;
...@@ -4365,7 +4365,9 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE ...@@ -4365,7 +4365,9 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
} }
IImage* newImage = createImage(format, ScreenSize); IImage* newImage = createImage(format, ScreenSize);
u8* pixels = static_cast<u8*>(newImage->lock()); u8* pixels = 0;
if (newImage)
pixels = static_cast<u8*>(newImage->lock());
if (pixels) if (pixels)
{ {
GLenum tgt=GL_FRONT; GLenum tgt=GL_FRONT;
...@@ -4418,14 +4420,15 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE ...@@ -4418,14 +4420,15 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
delete [] tmpBuffer; delete [] tmpBuffer;
} }
newImage->unlock(); if (newImage)
if (testGLError() || !pixels)
{ {
newImage->drop(); newImage->unlock();
return 0; if (testGLError() || !pixels)
{
newImage->drop();
return 0;
}
} }
return newImage; return newImage;
} }
......
...@@ -100,6 +100,7 @@ int main(int argumentCount, char * arguments[]) ...@@ -100,6 +100,7 @@ int main(int argumentCount, char * arguments[])
TEST(ioScene); TEST(ioScene);
// all driver checks // all driver checks
TEST(videoDriver); TEST(videoDriver);
TEST(screenshot);
TEST(drawPixel); TEST(drawPixel);
TEST(drawRectOutline); TEST(drawRectOutline);
TEST(guiDisabledMenu); TEST(guiDisabledMenu);
......
// Copyright (C) 2008-2011 Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
using namespace irr;
// Tests screenshots.
/** At the moment, this just verifies that the last frame of the animation produces the expected bitmap. */
bool testShots(video::E_DRIVER_TYPE type)
{
IrrlichtDevice *device = createDevice(type, core::dimension2d<u32>(160, 120), 32);
if (!device)
return true;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager * smgr = device->getSceneManager();
scene::IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
scene::IAnimatedMeshSceneNode* node;
if (!mesh)
return false;
node = smgr->addAnimatedMeshSceneNode(mesh);
if (!node)
return false;
node->setPosition(core::vector3df(20, 0, 30));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
node->setLoopMode(false);
(void)smgr->addCameraSceneNode();
// Just jump to the last frame since that's all we're interested in.
node->setMD2Animation(scene::EMAT_DEATH_FALLBACK);
node->setCurrentFrame((f32)(node->getEndFrame()));
node->setAnimationSpeed(0);
device->run();
driver->beginScene(true, true, video::SColor(255, 255, 255, 0));
smgr->drawAll();
driver->endScene();
for (u32 i=0; i<video::ECF_UNKNOWN; ++i)
{
video::IImage* img = driver->createScreenShot((video::ECOLOR_FORMAT)i);
logTestString("Color Format %d %ssupported\n", i, (img && img->getColorFormat() == i)?"":"un");
if (img)
img->drop();
}
device->closeDevice();
device->run();
device->drop();
return true;
}
bool screenshot()
{
testShots(video::EDT_OPENGL);
testShots(video::EDT_DIRECT3D9);
return true;
}
\ No newline at end of file
...@@ -161,7 +161,7 @@ static bool doTests() ...@@ -161,7 +161,7 @@ static bool doTests()
tmp.getAngle(), ref.getAngle()); tmp.getAngle(), ref.getAngle());
return false; return false;
} }
tmp = core::vector2d<T>(-1.53080559e-16, 2.49999523); tmp = core::vector2d<T>(static_cast<T>(-1.53080559e-16), static_cast<T>(2.49999523));
ref = core::vector2d<f64>(-1.53080559e-16, 2.49999523); ref = core::vector2d<f64>(-1.53080559e-16, 2.49999523);
if (!equals(tmp.getAngle(),ref.getAngle())) if (!equals(tmp.getAngle(),ref.getAngle()))
{ {
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
<Unit filename="renderTargetTexture.cpp" /> <Unit filename="renderTargetTexture.cpp" />
<Unit filename="sceneCollisionManager.cpp" /> <Unit filename="sceneCollisionManager.cpp" />
<Unit filename="sceneNodeAnimator.cpp" /> <Unit filename="sceneNodeAnimator.cpp" />
<Unit filename="screenshot.cpp" />
<Unit filename="serializeAttributes.cpp" /> <Unit filename="serializeAttributes.cpp" />
<Unit filename="skinnedMesh.cpp" /> <Unit filename="skinnedMesh.cpp" />
<Unit filename="softwareDevice.cpp" /> <Unit filename="softwareDevice.cpp" />
......
...@@ -125,6 +125,7 @@ ...@@ -125,6 +125,7 @@
<ClCompile Include="renderTargetTexture.cpp" /> <ClCompile Include="renderTargetTexture.cpp" />
<ClCompile Include="sceneCollisionManager.cpp" /> <ClCompile Include="sceneCollisionManager.cpp" />
<ClCompile Include="sceneNodeAnimator.cpp" /> <ClCompile Include="sceneNodeAnimator.cpp" />
<ClCompile Include="screenshot.cpp" />
<ClCompile Include="serializeAttributes.cpp" /> <ClCompile Include="serializeAttributes.cpp" />
<ClCompile Include="skinnedMesh.cpp" /> <ClCompile Include="skinnedMesh.cpp" />
<ClCompile Include="softwareDevice.cpp" /> <ClCompile Include="softwareDevice.cpp" />
......
...@@ -348,6 +348,10 @@ ...@@ -348,6 +348,10 @@
RelativePath=".\sceneNodeAnimator.cpp" RelativePath=".\sceneNodeAnimator.cpp"
> >
</File> </File>
<File
RelativePath=".\screenshot.cpp"
>
</File>
<File <File
RelativePath=".\serializeAttributes.cpp" RelativePath=".\serializeAttributes.cpp"
> >
......
...@@ -347,6 +347,10 @@ ...@@ -347,6 +347,10 @@
RelativePath=".\sceneNodeAnimator.cpp" RelativePath=".\sceneNodeAnimator.cpp"
> >
</File> </File>
<File
RelativePath=".\screenshot.cpp"
>
</File>
<File <File
RelativePath=".\serializeAttributes.cpp" RelativePath=".\serializeAttributes.cpp"
> >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment