[Bf-committers] File reading tech doc (was fix #1980)

Ton Roosendaal ton at blender.org
Wed Dec 8 15:11:51 CET 2004


Hi Jacques,

Thanks for the patch file, looking deeper into the problem I found out  
this error will happen on all platforms, caused by reading in a  
.B.blend file with a USER chunk, which isn't properly handled.

So; if you didn't have the AA fonts set before, reading the B.blend.zip  
as on our website will cause such errors.

Instead of patching this like you propose, I decided to clean up old  
mess involved with reading files in Blender. Our routines just patched  
& wrapped things beyond comprehension... so, for documentation  
pleasure, here's also how it should work in Blender. After my next  
commit, the flow and dependencies for calls will go as following.


Currently four different levels of routines for .blend file reading  
exist;

/* interface level */
1) BIF_init() -> calls 3
2) BIF_read_file() -> calls 11, optional 4
3) BIF_read_homefile() -> calls 11 or 12, and then 4
4) init_userdef_file()

/* kernel level */
11) BKE_read_file() -> calls 21, and then 14
12) BKE_read_file_from_memory() -> calls 22, and then 14
13) BKE_read_file_from_memfile() -> calls 23, and then 14
14) setup_app_data()

/* loader module level */
21) BLO_read_from_file() -> calls 24
22) BLO_read_from_memory() -> calls 24
23) BLO_read_from_memfile() -> calls 24

/* loader module, internal */
24) blo_read_file_internal()


Note:
- BIF_read_homefile() has additional UI initialize calls, like windows  
fullscreen and executing commandline options

- Reading from memory (12) only happens for the compiled-in .B.blend

- The "memfile" here is a name I gave to the undo "file" structure.  
Which is constructed out of memory chunks with basic compression  
features.

- the kernel function setup_app_data() sets globals like "current  
screen" and "current scene".

So far, so good. The levels as mentioned here clearly distinguish UI  
from kernel, and should enable for example game loading (runtime) or  
background (no UI) loading. In the past years however, 'bad level'  
dependencies were added, and especially the patches for 'file versions'  
were added in too many places. The latter is evidently a result of the  
problem that the "UserDef" struct cannot be initialized/patched if  
there's not a need for a UI.

Here's how the flow goes in four different cases:

----- Starting up Blender, in foreground with UI --------------------

- creator/creator.c, main() -> calls 1
- If the commandline contains a filename, it calls 11

----- Starting up Blender, in background without UI --------------------

- creator/creator.c, main() -> calls 11 if the commandline has a  
filename

Note: no Userdef is read, nor initialized. Please note that this was  
already an existing problem for using Yafray, not setting proper file  
paths in background mode. The Yafray paths don't belong in the User  
menu.

----- Starting up Blender as a runtime executable --------------------

This only has calls to 22

----- Loading a file from within the UI (with F1, CTRL+O, using  
pulldowns) -----

Only calls allowed to 2. It detects if a UserDef has been read too, and  
in that case the init_userdef_file() will be executed.

Hope this is understandable :)

-Ton-



On 8 Dec, 2004, at 11:25, Jacques Beaurain wrote:

> Hi,
>
> I figured this one out. Should be able to reproduce on vanilla system  
> on any platform where you start out without International Fonts  
> switched on. The crash happened on line 245 of FTF_TTFont.cpp. The  
> reason was that the SetFont member would not have been called at this  
> stage because fonts are only refreshed on startup at the moment. Here  
> is a patch that fixes this.
>
> Cheers,
> Jacques
> Index: source/blender/include/BIF_language.h
> ===================================================================
> RCS file:  
> /cvsroot/bf-blender/blender/source/blender/include/BIF_language.h,v
> retrieving revision 1.4
> diff -u -r1.4 BIF_language.h
> --- source/blender/include/BIF_language.h	20 Oct 2003 15:40:18  
> -0000	1.4
> +++ source/blender/include/BIF_language.h	8 Dec 2004 09:59:06 -0000
> @@ -35,18 +35,19 @@
>
>  struct BMF_Font;
>
> -int  read_languagefile(void);		/* usiblender.c */
> -void free_languagemenu(void);		/* usiblender.c */
> +int  read_languagefile(void);		/* language.c */
> +void free_languagemenu(void);		/* language.c */
>
> -void set_interface_font(char *str); /* headerbuttons.c */
> -void start_interface_font(void);	/* headerbuttons.c */
> -void lang_setlanguage(void);		/* usiblender.c */
> +void set_interface_font(char *str); /* language.c */
> +void start_interface_font(void);	/* language.c */
> +void refresh_interface_font(void);	/* language.c */
> +void lang_setlanguage(void);		/* language.c */
>
> -char *language_pup(void);
> -char *fontsize_pup(void);
> +char *language_pup(void);			/* language.c */
> +char *fontsize_pup(void);			/* language.c */
>
> -int BIF_DrawString(struct BMF_Font* font, char *str, int translate);
> -float BIF_GetStringWidth(struct BMF_Font* font, char *str, int  
> translate);
> +int BIF_DrawString(struct BMF_Font* font, char *str, int  
> translate);		/* language.c */
> +float BIF_GetStringWidth(struct BMF_Font* font, char *str, int  
> translate);	/* language.c */
>
>  #endif /* BIF_LANGUAGE_H */
>
> Index: source/blender/src/header_info.c
> ===================================================================
> RCS file:  
> /cvsroot/bf-blender/blender/source/blender/src/header_info.c,v
> retrieving revision 1.50
> diff -u -r1.50 header_info.c
> --- source/blender/src/header_info.c	11 Nov 2004 23:58:05 -0000	1.50
> +++ source/blender/src/header_info.c	8 Dec 2004 10:07:05 -0000
> @@ -900,6 +900,7 @@
>  		
>  			BKE_reset_undo();
>  			BKE_write_undo("original");	/* save current state */
> +			refresh_interface_font();
>  		}
>  		break;
>  	case 31: /* save default settings */
> Index: source/blender/src/language.c
> ===================================================================
> RCS file: /cvsroot/bf-blender/blender/source/blender/src/language.c,v
> retrieving revision 1.27
> diff -u -r1.27 language.c
> --- source/blender/src/language.c	8 Nov 2004 15:46:57 -0000	1.27
> +++ source/blender/src/language.c	8 Dec 2004 10:07:05 -0000
> @@ -348,6 +348,18 @@
>  }
>
>
> +void refresh_interface_font(void)
> +{
> +#ifdef INTERNATIONAL
> +	if(U.transopts & USER_DOTRANSLATE)
> +		start_interface_font();
> +	else
> +		G.ui_international = FALSE;
> +#else // INTERNATIONAL
> +	G.ui_international = FALSE;
> +#endif // INTERNATIONAL
> +}
> +
>  void free_languagemenu(void)
>  {
>  	LANGMenuEntry *lme= langmenu;
> Index: source/blender/src/usiblender.c
> ===================================================================
> RCS file: /cvsroot/bf-blender/blender/source/blender/src/usiblender.c,v
> retrieving revision 1.67
> diff -u -r1.67 usiblender.c
> --- source/blender/src/usiblender.c	4 Dec 2004 17:52:44 -0000	1.67
> +++ source/blender/src/usiblender.c	8 Dec 2004 10:07:05 -0000
> @@ -149,6 +149,7 @@
>  		undo_editmode_clear();
>  		BKE_reset_undo();
>  		BKE_write_undo("original");	/* save current state */
> +		refresh_interface_font();
>  	}
>  	else BIF_undo_push("Import file");
>  }
> @@ -279,13 +280,9 @@
>
>  #ifdef INTERNATIONAL
>  		read_languagefile();
> -	
> -		if(U.transopts & USER_DOTRANSLATE)
> -			start_interface_font();
> -		else
> -			G.ui_international = FALSE;
>  #endif // INTERNATIONAL
>
> +		refresh_interface_font();
>  	}
>
>  	return success;
> _______________________________________________
> 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



More information about the Bf-committers mailing list