Jump to content

Craft images


linuxgurugamer

Recommended Posts

I found this posting:

http://forum.kerbalspaceprogram.com/threads/119609-Manually-generating-ship-thumbnail

and it works well for a single ship.

however, i'm having a problem with generating a number of images all at once:


for (int i = 0; i < m_filesWithImages.Length; ++i) {
if (m_files [i].Contains (".craft")) {
string f = m_newDirectory + "/" + m_files [i];

if (System.IO.File.Exists (f)) {

var configFile = ConfigNode.Load (f);

ShipConstruct ship = new ShipConstruct ();
ship.LoadShip (configFile);

ThumbnailHelper.CaptureThumbnail (ship, 256, "tmp", m_files [i] + i.ToString());
ShipConstruction.CaptureThumbnail (ship, "tmp", m_files [i] + "-2-" + i.ToString ());


configFile = null;
ship = null;
}
}
}

The first one or two work fine, but then the images start to become a mishmosh of all the previous craft.

If I only do a single craft, there is no problem.

My guess is that the CraftThumbnail.TakeSnapshot function (which both the above functions use) is in a different thread and takes longer to generate the images than it takes to loop through that array

Another clue is that in the log, I see message like this:

Two-Stage Lander loaded

which are not from my mod, so maybe the craft has to be loaded first before taking the snapshot, and there is a race condition somewhere

I added some code to watch the png files to be sure they are done being written, but that didn't help

Any other ideas?

Edited by linuxgurugamer
Link to comment
Share on other sites

I found this posting:

http://forum.kerbalspaceprogram.com/threads/119609-Manually-generating-ship-thumbnail

and it works well for a single ship.

however, i'm having a problem with generating a number of images all at once:


for (int i = 0; i < m_filesWithImages.Length; ++i) {
if (m_files [i].Contains (".craft")) {
string f = m_newDirectory + "/" + m_files [i];

if (System.IO.File.Exists (f)) {

var configFile = ConfigNode.Load (f);

ShipConstruct ship = new ShipConstruct ();
ship.LoadShip (configFile);

ThumbnailHelper.CaptureThumbnail (ship, 256, "tmp", m_files [i] + i.ToString());
ShipConstruction.CaptureThumbnail (ship, "tmp", m_files [i] + "-2-" + i.ToString ());


configFile = null;
ship = null;
}
}
}

The first one or two work fine, but then the images start to become a mishmosh of all the previous craft.

If I only do a single craft, there is no problem.

My guess is that the CraftThumbnail.TakeSnapshot function (which both the above functions use) is in a different thread and takes longer to generate the images than it takes to loop through that array

Another clue is that in the log, I see message like this:

Two-Stage Lander loaded

which are not from my mod, so maybe the craft has to be loaded first before taking the snapshot, and there is a race condition somewhere

I added some code to watch the png files to be sure they are done being written, but that didn't help

Any other ideas?

On second thought, it might be that it hasn't finished clearing out the previous ship before I load the next one. But how can I tell if that's the problem, and if so, how can I prevent this from happening?

Link to comment
Share on other sites

After a lot of tests, I've been able to conclude that for some reason, loading multiple ships will, after loading 2 or 3 ships, start corrupting the loaded ships.

I'm not sure why yet. But what I've done is to load all the ships, but only make one thumbnail and it is bad, but if I load the same ship by itself and make the thumbnail, it's correct.

I tried adding a ship.Clear(), in the hope that it would clear whatever memory is being used, but that didn't help.

This happens even when the variable goes out of context and therefore the memory it uses is released.

Anybody have any suggestions?

Edit: Interesting observation. the "ship.LoadShip" actually loads the ship into the current scene. So what I'm guessing is happening is that all the ships are being loaded into the scene and mashed together.

Looks kind of interesting, but crashes the VAB

So, I'm trying to find the following:

  • A function to find the currently loaded ship and copy it
  • A function to clear the currently loaded ship

What I want to do is to first copy the currently loaded ship, clear it, then load each craft file and take a thumbnail snapshot, and finally to restore the originally loaded ship

Edited by linuxgurugamer
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...