www.quadsoftware.com
FAQ  FAQ   Search  Search   Memberlist  Memberlist   Usergroups  Usergroups
Register  ::  Log in Log in to check your private messages


Post new topic  Reply to topic
 Heap corruption... « View previous topic :: View next topic » 
Author Message
Guigui
PostPosted: Wed Aug 13, 2008 2:23 pm    Post subject: Heap corruption... Reply with quote



Joined: 21 Jul 2008
Posts: 15

Hi,

I'm having a breakpoint triggered at grome's exit in the debuguee, during the core shutdown process. My plugin is indeed the culprit, but i can't pinpoint what i'm doing wrong.

It's linked to the use of iTerrainZone::GetAssignedLayers(iTerrainMaterialLayer::TypeString()) which i use to create an image corresponding to the blending of all layers.

As soon as i use this function, any call to iTerrainMaterialLayer::GetMaterial() will trigger the breakpoint on exit.

I looked at the sdk examples (general export) to check how things were done there, and even if it's not really my goal, i tried to do the same operation with all iTerrainMaterialLayer in the project. I didn't use GetAssignedLayers but GetLayersNo and GetLayer from the iTerrainEd interface. It worked whether i used iTerrainMaterialLayer::GetMaterial() or not. My guess is i'm messing with ref counting for an interface maybe?


Here's a bit of code that makes it happen. The lines commented are the ones using the iTerrainEd interface instead (this one works). I just cycle through every iTerrainZone before the piece of code but the same way it's done in any plugin (including other working personnal plugins)

Code:
t_readonly_array<iEditorLayer*>* layers = currentZone->GetAssignedLayers(iTerrainMaterialLayer::TypeString());

for(uint k=0; k<layers->No(); k++)
//for(uint k=0; k< terrain_editor->GetLayersNo(iTerrainMaterialLayer::TypeString()); k++)
{
                        
   iTerrainMaterialLayer* material_layer = (iTerrainMaterialLayer*)(layers->Elem(k));
   //iTerrainMaterialLayer* material_layer = (iTerrainMaterialLayer*)terrain_editor->GetLayer(iTerrainMaterialLayer::TypeString(), k);

   const sMaterialDefinition* matDef = material_layer->GetMaterial( currentZone );

       // ... use info from material def (crash on exit even if this block is commented)

   //material_layer->CloseInterface();
}


in debuguee...

=======================================================
[START] Core release...
=======================================================
[CALL] RunScript: Scripts/shutdown.as
   Compiling script... [OK]
Shutting down the Object Editor application package...

[END] RunScript(Scripts/shutdown.as)
   Total script run [CPU: 0. sec]
[CALL] RunScript: Scripts/shutdown.as
   Compiling script... [OK]
Shutting down the Terrain Editor application package...
[END] RunScript(Scripts/shutdown.as)
   Total script run [CPU: 0. sec]
[CALL] RunScript: Scripts/shutdown.as    [ERROR] Opening the file.
[CALL] RunScript(Scripts/shutdown.as)    Error opening the file.
[CALL] RunScript: Scripts/shutdown.as    [ERROR] Opening the file.
[CALL] RunScript(Scripts/shutdown.as)    Error opening the file.'Grome.exe': Unloaded 'C:\Program Files\Grome Professional\Builder\Bin\BuilderSdk.cmod'
'Grome.exe': Unloaded 'C:\Program Files\Grome Professional\Plugins\ColladaStorage.plug'
'Grome.exe': Unloaded 'C:\WINDOWS\system32\wsock32.dll'
First-chance exception at 0x0377cad5 in Grome.exe: 0xC0000005: Access violation reading location 0x6f635f3d.



Any ideas ? Can you reproduce it ? I'm a bit lost Confused

As a side note, I also found strange that the GetTextureUVMap for a mask returns the same mapping as the color texture, with offset, rotation and tiling. I just did my own standard mapping but i wasn't expecting this. Can you confirm this is reproducible too and not intended?

I use the latest grome release as of today.

Thanks for your help.

Regards,
Guillaume R.
Back to top
View user's profile Send private message
ALicu
PostPosted: Wed Aug 13, 2008 2:55 pm    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

Hi,

You can check out the simple text, OSG and also COLLADA exporters as they use GetAssignedLayers and GetMaterial. To be noted that material_layer->CloseInterface should not be called when GetAssignedLayers is used (should be called when terrain_editor->GetLayer is used, in the second variant). But you probably knew that (since you've commented it in the code).

The above mentioned plugins work ok without any crash.

Is the commented code working fine (the variant with terrain_editor->GetLayer)?

Do you open the interface to one of the texture channels images? example: texture_channel->source->GetImage(). In this case you should close the interface to that image.

Also don't forget to close the interfaces to any zones, images or other objects you've opened.

I cannot see anything wrong with your code. Please check the above mentioned plugins and see what differs compared with your plugin code.

I know that managing plugin interfaces is sometimes frustrating. In future versions we plan to add some sort of interface garbage collecting.

Let me know if you find anything else.

Regards,
Adrian L.

PS: I will also look into the GetTextureUVMap issue, it should return proper unit texmap.
Back to top
View user's profile Send private message
ALicu
PostPosted: Wed Aug 13, 2008 3:07 pm    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

About GetTextureUVMap, yes that was an issue that is now fixed (for mask and simple color unit texture coordinates are now returned). Thanks for pointing that out.
Back to top
View user's profile Send private message
Guigui
PostPosted: Wed Aug 13, 2008 4:42 pm    Post subject: Resolved ! Reply with quote



Joined: 21 Jul 2008
Posts: 15

Hi,

Thank you for pointing out the simple text export sample, i finally figured the problem. It was indeed a missing gCloseInterfaces on the GetTerrainZones() elements. Embarassed Didn't notice before since other plugins were working and i have the bad practice of copy 'n pasting...

Thanks again, was driving me crazy.

Regards,
Guillaume R
Back to top
View user's profile Send private message
ALicu
PostPosted: Wed Aug 13, 2008 4:45 pm    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

Hi, glad i could help. This is actually one thing that bugs me. Working with interfaces should be safe and should not require the user to manually manage their reference counts. We are really thinking of a solution to garbage collect the interfaces. Hopefully we will be able to make this in a soon to be launched version.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Based on a template by Dustin Baccetti
Powered by phpBB © 2001, 2005 phpBB Group