Crystal Space
Welcome, Guest. Please login or register.
October 22, 2017, 09:10:18 am

Login with username, password and session length
Search:     Advanced search
9063 Posts in 2051 Topics by 77641 Members
Latest Member: Adaomaraanan848
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  csScreenShot reference problems
« previous next »
Pages: [1] Print
Author Topic: csScreenShot reference problems  (Read 1885 times)
Full Member
Posts: 122

View Profile Email
« on: October 02, 2005, 04:54:32 am »

I am having a problem getting a screenshot from either g2d or making a custom csScreenShot object and saving it using iImageIO::Save()

Here is the code I am using:

        TerraDebug::terraDebug("Taking ss...");
        iGraphics2D *g = cc->GetGraphics3D()->GetDriver2D();
        csScreenShot *ss;

        csRef<iImageIO> imgio = CS_QUERY_REGISTRY(cc->getObjectRegistry(), iImageIO);


        ss = new csScreenShot(g);

        imgio->Save(ss, "image/png");

        TerraDebug::terraDebugColored("Screenshot saved!");

And I get this error:

/usr/local/include/crystalspace/csutil/ref.h:103: failed assertion '(("csPtr<> was not assigned to a csRef<> prior destruction") && (obj == (T*)0xffffffff))'

And the same happens if I use g2d->ScreenShot() to get the image.

What's up?  CVS CS, by the way, about 3 weeks old.
Hero Member
Posts: 1706

View Profile
« Reply #1 on: October 02, 2005, 05:37:28 am »

The problem is the call to imgio->Save(). That one returns a databuffer and you must assign that to a variable like this:

csRef<iDataBuffer> buf = imgio->Save (...);

Otherwise what is the point of using Save() if you don't remember the thing you save?

Full Member
Posts: 122

View Profile Email
« Reply #2 on: October 02, 2005, 05:49:50 pm »

Ah yes, I should have noticed that, sorry for wasting your time.

And for those who happen to stumble upon this post,  here is a nice routine that will save the screenshots as jpegs them starting from screenshot0.jpg and increment the number during the game, but it will restart the counter when you terminate the game:

        iGraphics2D *g = cc->GetGraphics3D()->GetDriver2D();
        csRef<iImage> img;
        csRef<iImageIO> imgio;
        csRef<iDataBuffer> data;
        csRef<iVFS> vfs;
        char str[14];
        static short int num = 0;       
        imgio = CS_QUERY_REGISTRY(cc->getObjectRegistry(), iImageIO);
        vfs = CS_QUERY_REGISTRY(cc->getObjectRegistry(), iVFS);
        //grab the screenshot as a databuffer
        img = g->ScreenShot();       
        data = imgio->Save(img, "image/jpg");


        sprintf(str, "screenshot%d.jpg", num++);
        //Write the data to a file...`
        if(!vfs->WriteFile(str, data->GetData(), data->GetSize()))
            TerraDebug::terraError("Could not save screenshot!");
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 7.485 seconds with 16 queries.