[Bf-committers] 64-bit bug loading .blend files containing scriptlinks

Ken Hughes khughes at pacific.edu
Sat Nov 19 16:21:01 CET 2005

Ton Roosendaal wrote:
> Hi,
> this is struct ScriptLink:
> typedef struct ScriptLink {
>     struct ID **scripts;
>     short *flag;
>     short actscript, totscript;
>     int pad;
> } ScriptLink;
> It only has 2 pointers... further, Blender structs are stuffed with  
> pointers, on reading a 32 bits file, the 64 bits Blender DNA should  
> detect this and reallocate the struct with correct data in it. The only  
> thing that could use testing is endianness and 64 bits. But I assume  
> the 32 bits file you tried is from a linux intel system too?


This is how the script link is written in writefile.c:

static void write_scriptlink(WriteData *wd, ScriptLink *slink)
     writedata(wd, DATA, sizeof(void *)*slink->totscript, slink->scripts);
     writedata(wd, DATA, sizeof(short)*slink->totscript, slink->flag);

the slink->script is written based on the structure, which is an array 
of pointers.  It reads this in again on load, but again assumes it's
an array of 64-bit pointers when it's used.

I tested on two linux intel systems.


> On 18 Nov, 2005, at 23:48, Ken Hughes wrote:
>> This is the first real 64-bit bug I've seen (which is good).  A 
>> .blend  file from a 32-bit system which contains three scriptlinks is 
>> loaded  on my AMD64 system under linux.  As read_struct() load the 
>> file, it  gets to the structure for the scriptlinks and allocates 
>> memory for 3  pointers for a total of 12 bytes.  Later, when 
>> lib_link_scriptlink()  is called, it goes through trying to relink the 
>> objects, but thinks  slink->scripts is pointer at 8-byte pointers.  
>> The result is memory  errors on exit (either from MEM_freen() or 
>> glibc).  For now I've  verified using a hack in lib_link_scriptlink() 
>> that correctly  converting the 32-bit pointers to 64-bit pointers and 
>> reallocating the  proper storage fixes the problem.
>> Any suggestions what to do?  I'm not familiar with this part of the  
>> source tree at all.
>> Ken
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at projects.blender.org
>> http://projects.blender.org/mailman/listinfo/bf-committers
> ------------------------------------------------------------------------ --
> Ton Roosendaal  Blender Foundation ton at blender.org  http://www.blender.org
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-committers

More information about the Bf-committers mailing list