PDA

View Full Version : Get “Assertion Failure” from Tstream save to image data.



azrael11
08-03-2015, 02:29 PM
Hi, long time to show my presence here....
To many problems....
Btw...

I try to add stream image to material library in glscene 1.3 for delphi 7.
Everything seems to work fine when i save the image to file and and add it to material library.


vars
strm: Tstream;
i: integer;
img: TImageData;
ext: string;

//
MyArchiveManager:= TGLSArchiveManager.Create(MainForm);
MyArchiveManager.Archives.Add.Name:= 'name1';
MyArchiveManager.Archives[0].LoadFromFile(ProgramPath + Media_Path + 'loading.zlib');


for i:= 0 to MyArchiveManager.Archives[0].ContentList.Count - 1 do
begin
if (i> 0) and (i< 8) then
begin
strm:= MyArchiveManager.Archives[0].GetContent('loading/' + Loading_Materials[i] + '.png');
InitImage(img); //Initiliazation of image Vampire Image Library
ext:= DetermineStreamFormat(strm); //Determine if the file has proper ext
if ext<> '' then
begin
LoadImageFromStream(strm,img); //Load the image from stream and put in img
ConvertImage(img,ifA8Gray8); //convert it to gray
SaveImageToStream(ext,strm,img); // save the gray image to old stream again
//SaveImageToFile(ProgramPath + 'media\' + Loading_Materials[i] + '_grey.png',img);
AddMaterial(Matlib_Loading,strm,Loading_Materials[i] + '_grey',false,''); //false= not to glow the image... // see below for the procedure
//AddMaterial(MatLib_Loading,ProgramPath + 'media\' + Loading_Materials[i] + '_grey.png',Loading_Materials[i] + '_grey');
end;
//SysUtils.DeleteFile(ProgramPath + 'media\' + Loading_Materials[i] + '_grey.png');
FreeImage(img); //Free and nil img
FreeAndNil(strm); //Free and nil the stream...
end;
end;

But when i Use the stream then i get this error "Assertion Failure".
Something i miss here... but i can't find... what...

The full error is.. "Assertion Failure in GLTexture.pas in line 923..
And if i continue run the program by pressing ok in message then shows me
the image in white box and continue without errors...




function AddMaterial(aMatLib: TGlMaterialLibrary; aStreamName: TStream; aMaterialName: string; Glow: Boolean; GlowColor: String): TGlLibMaterial; overload;
var
i: integer;
begin
if Glow= False then
begin
result := aMatLib.Materials.Add;
with result do
begin
with Material do
begin
MaterialOptions := [moIgnoreFog, moNoLighting];
Texture.Disabled := false;
Texture.TextureMode:= tmModulate;
BlendingMode := bmTransparency;
with FrontProperties do
begin
Ambient.SetColor(1, 1, 1, 1);
Diffuse.SetColor(1, 1, 1, 1);
Emission.SetColor(1, 1, 1, 1);
Specular.SetColor(1, 1, 1, 1);
end;
Texture.ImageClassName := 'TGLCompositeImage';
aStreamName.Position:= 0; //This is what is missing
TGLCompositeImage(Texture.Image).LoadFromStream(aS treamName);
end;
Name:= aMaterialName
end;
end
else
begin
result := aMatLib.Materials.Add;
with result do
begin
with Material do
begin
MaterialOptions := [moIgnoreFog, moNoLighting];
Texture.Disabled := false;
Texture.TextureMode:= tmAdd;
BlendingMode := bmTransparency;
with FrontProperties do
begin
Ambient.SetColor(0, 0, 0, 1);
if GlowColor= 'red' then
Diffuse.SetColor(0.255, 0, 0, 1)
else if GlowColor= 'pink' then
Diffuse.SetColor(0.255, 0, 0.255, 1)
else if GlowColor= 'white' then
Diffuse.SetColor(0.255, 0.255, 0.255, 1)
else if GlowColor= 'blue' then
Diffuse.SetColor(0, 0, 0.255, 1)
else if GlowColor= 'black' then
Diffuse.SetColor(0, 0, 0, 1)
else if GlowColor= 'green' then
Diffuse.SetColor(0.030, 0.170, 0.30, 1)
else if GlowColor= 'orange' then
Diffuse.SetColor(0.255, 0.170, 0.030, 1)
else if GlowColor= 'brown' then
Diffuse.SetColor(0.180, 0.100, 0, 1)
else if GlowColor= 'yellow' then
Diffuse.SetColor(0.255, 0.255, 0, 1)
else if GlowColor= 'lime' then
Diffuse.SetColor(0, 0.255, 0, 1)
else if GlowColor= 'teal' then
Diffuse.SetColor(0.120, 0.160, 0.140, 1)
else if GlowColor= 'darkgray' then
Diffuse.SetColor(0.100, 0.100, 0.100, 1)
else if GlowColor= 'lightgray' then
Diffuse.SetColor(0.200, 0.200, 0.200, 1);
Emission.SetColor(0, 0, 0, 1);
Specular.SetColor(0, 0, 0, 1);
end;
Texture.ImageClassName := 'TGLCompositeImage';
aStreamName.Position:= 0; //This is what is missing
TGLCompositeImage(Texture.Image).LoadFromStream(aS treamName);
end;
Name:= aMaterialName + '_gl';
end;
end;
end;

SilverWarior
08-03-2015, 06:18 PM
What happens if you save that picture into file from the stream itself using SaveToFile method and then loading the image from file? Do you still get the same error?

Also does SaveImageToStream method moves the stream position to 0 before saving the data or does it just add the image to the end of the stream?

Similar question for method AddMaterial. Does it automatically moves the stream position to 0 before reading the data?

azrael11
10-03-2015, 12:55 PM
What happens if you save that picture into file from the stream itself using SaveToFile method and then loading the image from file? Do you still get the same error?

Also does SaveImageToStream method moves the stream position to 0 before saving the data or does it just add the image to the end of the stream?

Similar question for method AddMaterial. Does it automatically moves the stream position to 0 before reading the data?

Oh
The position set... i use Seek...
The error finds in AddMaterial that doesn't move the stream position to 0

Thank you Silver Warior... this question is SOLVED ...
I fix the above code to show my error

Thank you again...

SilverWarior
10-03-2015, 04:32 PM
I'm glad I could be of help.

Also since you are reusing existing stream it might not be a bad idea to set its size to 0 before storing the data (greyed image) in it the second time. Why?
If the size of that data is smaller than the size of stream you might end up with new data to be stored on the beggining of the stream and some renmants of old dta at the end of the stream. And this could lead to some unpredicatable behavior of your program which would probably be hard to debug.
Naturally this completly depends on how method that stores the data into the stream works (does it adjust the size of the stream or does not).

azrael11
11-03-2015, 04:35 PM
I'm glad I could be of help.

Also since you are reusing existing stream it might not be a bad idea to set its size to 0 before storing the data (greyed image) in it the second time. Why?
If the size of that data is smaller than the size of stream you might end up with new data to be stored on the beggining of the stream and some renmants of old dta at the end of the stream. And this could lead to some unpredicatable behavior of your program which would probably be hard to debug.
Naturally this completly depends on how method that stores the data into the stream works (does it adjust the size of the stream or does not).

As you can see from above the stream when ends the works if free and nil completly...
And yes it is adjust the size after you tell me about the position ;) ...

Thank you again...

SilverWarior
11-03-2015, 07:00 PM
No problem. I always try to help if I can.