]> O.S.I.I.S - jp/crow.git/commitdiff
prevent SvgPicture to cause exception if picture not loaded
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 18 Mar 2021 12:50:38 +0000 (13:50 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 18 Mar 2021 12:50:38 +0000 (13:50 +0100)
Crow/Crow.csproj
Crow/src/Fill/SvgPicture.cs
Directory.Build.props

index f09f66dc8636f2f204d381645e878be7d9533c3a..9cff5e2dbf62532ef61acc279d6abdc2e397d7d4 100644 (file)
@@ -23,7 +23,7 @@
                <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
                <GenerateDocumentationFile>true</GenerateDocumentationFile>
                <NoWarn>$(NoWarn);1591;1587;1570;1572;1573;1574</NoWarn>
-               <DefineConstants>_DESIGN_MODE;_MEASURE_TIME</DefineConstants>           
+               <DefineConstants>DESIGN_MODE;_MEASURE_TIME;_DEBUG_HIGHLIGHT_FOCUS</DefineConstants>             
                <EnableDefaultItems>false</EnableDefaultItems>
                <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
                <!--<AllowUnsafeBlocks>true</AllowUnsafeBlocks>-->
@@ -51,7 +51,7 @@
        </ItemGroup>
 
        <ItemGroup>
-               <Content Include="$(SolutionDir)Images\crow.png" Pack="true" PackagePath="" />
+               <Content Include="..\Images\crow.png" Pack="true" PackagePath="" />
                <Compile Include="src\**\*.cs" Exclude="src\Mono.Cairo\NativeMethods-internal.cs" />
                <EmbeddedResource Include="Templates\*.*">
                        <LogicalName>Crow.%(Filename).template</LogicalName>
index 4f378be44972356c5800f91211debee47707793c..fcd5c4d25c19e1f5c60b32c53d4236ae414eb2d4 100644 (file)
@@ -27,17 +27,20 @@ namespace Crow
                public SvgPicture (string path) : base(path) {}
                #endregion
 
-               void load (Interface iFace)
-               {                       
+               bool load (Interface iFace)
+               {
+                       if (string.IsNullOrEmpty(Path))
+                               return false;
                        if (iFace.sharedPictures.ContainsKey (Path)) {
                                sharedPicture sp = iFace.sharedPictures [Path];
                                hSVG = (Rsvg.Handle)sp.Data;
                                Dimensions = sp.Dims;
-                               return;
+                               return true;
                        }
                        using (Stream stream = iFace.GetStreamFromPath (Path))
                                load (stream);
                        iFace.sharedPictures [Path] = new sharedPicture (hSVG, Dimensions);
+                       return true;
                }
                void load (Stream stream) {
                        using (BinaryReader sr = new BinaryReader (stream)) {
@@ -61,7 +64,8 @@ namespace Crow
                public override void SetAsSource (Interface iFace, Context ctx, Rectangle bounds = default(Rectangle))
                {
                        if (hSVG == null)
-                               load (iFace);
+                               if (!load (iFace))
+                                       return;
 
                        float widthRatio = 1f;
                        float heightRatio = 1f;
@@ -101,7 +105,8 @@ namespace Crow
                public override void Paint (Interface iFace, Context gr, Rectangle rect, string subPart = "")
                {
                        if (hSVG == null)
-                               load (iFace);
+                               if (!load (iFace))
+                                       return;
 
                        float widthRatio = 1f;
                        float heightRatio = 1f;
index 89659e1d463c1acbb0296f1818d2327deedcb3e9..650c49bdcdceba1856dbd7c882037cb3dae1fb3e 100644 (file)
@@ -1,6 +1,5 @@
 <Project>
        <PropertyGroup>
-               <SolutionDir>$(MSBuildThisFileDirectory)</SolutionDir>
                <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
                <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)\</IntermediateOutputPath>
                <License>MIT</License>