Crystal Space
Welcome, Guest. Please login or register.
August 21, 2014, 01:25:09 pm

Login with username, password and session length
Search:     Advanced search
9012 Posts in 2050 Topics by 8331 Members
Latest Member: Donasand
* 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 1441 times)
muffinpeddler
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:

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

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

        g->BeginDraw();

        ss = new csScreenShot(g);

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

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

And I get this error:

Code:
/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.
Logged
jorrit
Administrator
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:

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

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

Greetings,
Logged
muffinpeddler
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:

Code:
        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");

        vfs->ChDir("/terra/saves/screens/");

        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!");
            return;
        }       
Logged
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 4.804 seconds with 13 queries.