~ubuntu-branches/ubuntu/wily/mupen64plus-video-rice/wily-proposed

« back to all changes in this revision

Viewing changes to debian/patches/highres_memcorruption.patch

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2011-08-14 17:07:19 UTC
  • Revision ID: james.westby@ubuntu.com-20110814170719-0jfo1wcnysg6vzc7
Tags: 1.99.4-4
* debian/patches:
  - Rewrite highres_memcorruption.patch to prevent further crashes and texture
    corruptions

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Description: fix crash in loading Celda 2009 hi-res texture pack for Zelda Ocarina of Time
2
 
Author: Richard Goedeken <Richard@fascinationsoftware.com>
 
1
Description: Scale highres textures by precalculated scaleShift exponent
 
2
 The highres textures should be created in a buffer with the size calculated
 
3
 from the desired native size and the size of the highres texture. The size
 
4
 used here should be 2**scaleShift as calculated by FindScaleFactor. This
 
5
 information is later used to correctly clamp and mirror textures. Therefore,
 
6
 (2**scaleShift)*(Width|Height)ToCreate is the size of the final texture and
 
7
 (2**scaleShift)*(Width|Height)ToLoad is the size of the texture information
 
8
 which are loaded from the external image. The mirror factor is already part of
 
9
 the (Width|Height)ToCreate value and it must not be multiplied by it again to
 
10
 get the texture buffer size.
 
11
 .
 
12
 Doing it differently will result in segfaults or corrupted textures.
 
13
Origin: backport, https://bitbucket.org/richard42/mupen64plus-video-rice/changeset/d1cc49eac47d
 
14
Author: Sven Eckelmann <sven@narfation.org>
3
15
 
4
16
---
5
17
diff --git a/src/TextureFilters.cpp b/src/TextureFilters.cpp
6
 
index e6adc5e115ac8b368544f974d2ca598366caa04c..20f904d8be25a2073b9527202342b0848c72a4d4 100644
 
18
index e6adc5e115ac8b368544f974d2ca598366caa04c..3b728c78c463d4bae8965689189c57fbab5b4c1c 100644
7
19
--- a/src/TextureFilters.cpp
8
20
+++ b/src/TextureFilters.cpp
9
21
@@ -1288,6 +1288,7 @@ void FindAllHiResTextures(void)
14
26
         return;
15
27
     }
16
28
     else
17
 
@@ -1849,8 +1850,8 @@ void LoadHiresTexture( TxtrCacheEntry &entry )
 
29
@@ -1849,15 +1850,14 @@ void LoadHiresTexture( TxtrCacheEntry &entry )
18
30
     }
19
31
 
20
32
     // calculate the texture size magnification by comparing the N64 texture size and the hi-res texture size
21
33
-    int scalex = width / (int)entry.ti.WidthToCreate;
22
34
-    int scaley = height / (int)entry.ti.HeightToCreate;
23
 
+    int scalex = width / (int)entry.ti.WidthToLoad;
24
 
+    int scaley = height / (int)entry.ti.HeightToLoad;
 
35
+    int scale = 1 << scaleShift;
25
36
     int mirrorx = 1;
26
37
     int mirrory = 1;
27
38
     if (entry.ti.WidthToCreate/entry.ti.WidthToLoad == 2) mirrorx = 2;
 
39
     if (entry.ti.HeightToCreate/entry.ti.HeightToLoad == 2) mirrory = 2;
 
40
-    entry.pEnhancedTexture = CDeviceBuilder::GetBuilder()->CreateTexture(entry.ti.WidthToCreate*scalex*mirrorx, entry.ti.HeightToCreate*scaley*mirrory);
 
41
+    entry.pEnhancedTexture = CDeviceBuilder::GetBuilder()->CreateTexture(entry.ti.WidthToCreate*scale, entry.ti.HeightToCreate*scale);
 
42
     DrawInfo info;
 
43
-
 
44
+    
 
45
     if( entry.pEnhancedTexture && entry.pEnhancedTexture->StartUpdate(&info) )
 
46
     {
 
47
 
 
48
@@ -1913,22 +1913,22 @@ void LoadHiresTexture( TxtrCacheEntry &entry )
 
49
 
 
50
         if (mirrorx == 2)
 
51
         {
 
52
-            //printf("Mirror: ToCreate: (%d,%d) ToLoad: (%d,%d) Scale: (%i,%i) Mirror: (%i,%i) Size: (%i,%i) Mask: %i\n", entry.ti.WidthToCreate, entry.ti.HeightToCreate, entry.ti.WidthToLoad, entry.ti.HeightToLoad, scalex, scaley, mirrorx, mirrory, width, height, entry.ti.maskS+scaleShift);
 
53
+            //printf("Mirror: ToCreate: (%d,%d) ToLoad: (%d,%d) Scale: (%i,%i) Mirror: (%i,%i) Size: (%i,%i) Mask: %i\n", entry.ti.WidthToCreate, entry.ti.HeightToCreate, entry.ti.WidthToLoad, entry.ti.HeightToLoad, scale, scale, mirrorx, mirrory, width, height, entry.ti.maskS+scaleShift);
 
54
             gTextureManager.Mirror(info.lpSurface, width, entry.ti.maskS+scaleShift, width*2, width*2, height, S_FLAG, 4 );
 
55
         }
 
56
 
 
57
         if (mirrory == 2)
 
58
         {
 
59
-            //printf("Mirror: ToCreate: (%d,%d) ToLoad: (%d,%d) Scale: (%i,%i) Mirror: (%i,%i) Size: (%i,%i) Mask: %i\n", entry.ti.WidthToCreate, entry.ti.HeightToCreate, entry.ti.WidthToLoad, entry.ti.HeightToLoad, scalex, scaley, mirrorx, mirrory, width, height, entry.ti.maskT+scaleShift);
 
60
+            //printf("Mirror: ToCreate: (%d,%d) ToLoad: (%d,%d) Scale: (%i,%i) Mirror: (%i,%i) Size: (%i,%i) Mask: %i\n", entry.ti.WidthToCreate, entry.ti.HeightToCreate, entry.ti.WidthToLoad, entry.ti.HeightToLoad, scale, scale, mirrorx, mirrory, width, height, entry.ti.maskT+scaleShift);
 
61
             gTextureManager.Mirror(info.lpSurface, height, entry.ti.maskT+scaleShift, height*2, entry.pEnhancedTexture->m_dwCreatedTextureWidth, height, T_FLAG, 4 );
 
62
         }
 
63
 
 
64
-        if( entry.ti.WidthToCreate*scalex*mirrorx < entry.pEnhancedTexture->m_dwCreatedTextureWidth )
 
65
+        if( entry.ti.WidthToCreate*scale < entry.pEnhancedTexture->m_dwCreatedTextureWidth )
 
66
         {
 
67
             // Clamp
 
68
             gTextureManager.Clamp(info.lpSurface, width, entry.pEnhancedTexture->m_dwCreatedTextureWidth, entry.pEnhancedTexture->m_dwCreatedTextureWidth, height, S_FLAG, 4 );
 
69
         }
 
70
-        if( entry.ti.HeightToCreate*scaley*mirrory < entry.pEnhancedTexture->m_dwCreatedTextureHeight )
 
71
+        if( entry.ti.HeightToCreate*scale < entry.pEnhancedTexture->m_dwCreatedTextureHeight )
 
72
         {
 
73
             // Clamp
 
74
             gTextureManager.Clamp(info.lpSurface, height, entry.pEnhancedTexture->m_dwCreatedTextureHeight, entry.pEnhancedTexture->m_dwCreatedTextureWidth, height, T_FLAG, 4 );