Browse Source

Fix a crash issue when attempting to draw invalid item.

This can happen when using UIItem as interfaces etc.
BenDol 6 years ago
parent
commit
9f7aafac0b
3 changed files with 23 additions and 19 deletions
  1. 17
    17
      modules/game_healthinfo/healthinfo.lua
  2. 2
    2
      modules/gamelib/player.lua
  3. 4
    0
      src/client/item.cpp

+ 17
- 17
modules/game_healthinfo/healthinfo.lua View File

@@ -1,21 +1,21 @@
1 1
 Icons = {}
2
-Icons[1] = { tooltip = tr('You are poisoned'), path = '/images/game/states/poisoned', id = 'condition_poisoned' }
3
-Icons[2] = { tooltip = tr('You are burning'), path = '/images/game/states/burning', id = 'condition_burning' }
4
-Icons[4] = { tooltip = tr('You are electrified'), path = '/images/game/states/electrified', id = 'condition_electrified' }
5
-Icons[8] = { tooltip = tr('You are drunk'), path = '/images/game/states/drunk', id = 'condition_drunk' }
6
-Icons[16] = { tooltip = tr('You are protected by a magic shield'), path = '/images/game/states/magic_shield', id = 'condition_magic_shield' }
7
-Icons[32] = { tooltip = tr('You are paralysed'), path = '/images/game/states/slowed', id = 'condition_slowed' }
8
-Icons[64] = { tooltip = tr('You are hasted'), path = '/images/game/states/haste', id = 'condition_haste' }
9
-Icons[128] = { tooltip = tr('You may not logout during a fight'), path = '/images/game/states/logout_block', id = 'condition_logout_block' }
10
-Icons[256] = { tooltip = tr('You are drowning'), path = '/images/game/states/drowning', id = 'condition_drowning' }
11
-Icons[512] = { tooltip = tr('You are freezing'), path = '/images/game/states/freezing', id = 'condition_freezing' }
12
-Icons[1024] = { tooltip = tr('You are dazzled'), path = '/images/game/states/dazzled', id = 'condition_dazzled' }
13
-Icons[2048] = { tooltip = tr('You are cursed'), path = '/images/game/states/cursed', id = 'condition_cursed' }
14
-Icons[4096] = { tooltip = tr('You are strengthened'), path = '/images/game/states/strengthened', id = 'condition_strengthened' }
15
-Icons[8192] = { tooltip = tr('You may not logout or enter a protection zone'), path = '/images/game/states/protection_zone_block', id = 'condition_protection_zone_block' }
16
-Icons[16384] = { tooltip = tr('You are within a protection zone'), path = '/images/game/states/protection_zone', id = 'condition_protection_zone' }
17
-Icons[32768] = { tooltip = tr('You are bleeding'), path = '/images/game/states/bleeding', id = 'condition_bleeding' }
18
-Icons[65536] = { tooltip = tr('You are hungry'), path = '/images/game/states/hungry', id = 'condition_hungry' }
2
+Icons[PlayerStates.Poison] = { tooltip = tr('You are poisoned'), path = '/images/game/states/poisoned', id = 'condition_poisoned' }
3
+Icons[PlayerStates.Burn] = { tooltip = tr('You are burning'), path = '/images/game/states/burning', id = 'condition_burning' }
4
+Icons[PlayerStates.Energy] = { tooltip = tr('You are electrified'), path = '/images/game/states/electrified', id = 'condition_electrified' }
5
+Icons[PlayerStates.Drunk] = { tooltip = tr('You are drunk'), path = '/images/game/states/drunk', id = 'condition_drunk' }
6
+Icons[PlayerStates.ManaShield] = { tooltip = tr('You are protected by a magic shield'), path = '/images/game/states/magic_shield', id = 'condition_magic_shield' }
7
+Icons[PlayerStates.Paralyze] = { tooltip = tr('You are paralysed'), path = '/images/game/states/slowed', id = 'condition_slowed' }
8
+Icons[PlayerStates.Haste] = { tooltip = tr('You are hasted'), path = '/images/game/states/haste', id = 'condition_haste' }
9
+Icons[PlayerStates.Swords] = { tooltip = tr('You may not logout during a fight'), path = '/images/game/states/logout_block', id = 'condition_logout_block' }
10
+Icons[PlayerStates.Drowning] = { tooltip = tr('You are drowning'), path = '/images/game/states/drowning', id = 'condition_drowning' }
11
+Icons[PlayerStates.Freezing] = { tooltip = tr('You are freezing'), path = '/images/game/states/freezing', id = 'condition_freezing' }
12
+Icons[PlayerStates.Dazzled] = { tooltip = tr('You are dazzled'), path = '/images/game/states/dazzled', id = 'condition_dazzled' }
13
+Icons[PlayerStates.Cursed] = { tooltip = tr('You are cursed'), path = '/images/game/states/cursed', id = 'condition_cursed' }
14
+Icons[PlayerStates.PartyBuff] = { tooltip = tr('You are strengthened'), path = '/images/game/states/strengthened', id = 'condition_strengthened' }
15
+Icons[PlayerStates.PzBlock] = { tooltip = tr('You may not logout or enter a protection zone'), path = '/images/game/states/protection_zone_block', id = 'condition_protection_zone_block' }
16
+Icons[PlayerStates.Pz] = { tooltip = tr('You are within a protection zone'), path = '/images/game/states/protection_zone', id = 'condition_protection_zone' }
17
+Icons[PlayerStates.Bleeding] = { tooltip = tr('You are bleeding'), path = '/images/game/states/bleeding', id = 'condition_bleeding' }
18
+Icons[PlayerStates.Hungry] = { tooltip = tr('You are hungry'), path = '/images/game/states/hungry', id = 'condition_hungry' }
19 19
 
20 20
 healthInfoWindow = nil
21 21
 healthBar = nil

+ 2
- 2
modules/gamelib/player.lua View File

@@ -133,7 +133,7 @@ function Player:getItemsCount(itemId)
133 133
   return count
134 134
 end
135 135
 
136
-function Player:hasState(_state, states)
136
+function Player:hasState(state, states)
137 137
   if not states then
138 138
     states = self:getStates()
139 139
   end
@@ -143,7 +143,7 @@ function Player:hasState(_state, states)
143 143
     if pow > states then break end
144 144
 
145 145
     local states = bit32.band(states, pow)
146
-    if states == _state then
146
+    if states == state then
147 147
       return true
148 148
     end
149 149
   end

+ 4
- 0
src/client/item.cpp View File

@@ -272,6 +272,10 @@ ItemPtr Item::clone()
272 272
 
273 273
 void Item::calculatePatterns(int& xPattern, int& yPattern, int& zPattern)
274 274
 {
275
+    // Avoid crashes with invalid items
276
+    if(!isValid())
277
+        return;
278
+
275 279
     if(isStackable() && getNumPatternX() == 4 && getNumPatternY() == 2) {
276 280
         if(m_countOrSubType <= 0) {
277 281
             xPattern = 0;

Loading…
Cancel
Save