summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-07-20 01:16:59 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-07-20 01:16:59 +0000
commit1bf17bc6fdf7ce3cf037b9c56d61da82f5956aab (patch)
tree61d1387d9d9980087a57bc3f0fe3b64a86bb8d7a
parent4bb50b23f21075ccb57426a2e04ca637ed56994f (diff)
downloadhercules-1bf17bc6fdf7ce3cf037b9c56d61da82f5956aab.tar.gz
hercules-1bf17bc6fdf7ce3cf037b9c56d61da82f5956aab.tar.bz2
hercules-1bf17bc6fdf7ce3cf037b9c56d61da82f5956aab.tar.xz
hercules-1bf17bc6fdf7ce3cf037b9c56d61da82f5956aab.zip
* Simplified the search in pop_timer_heap and added more debug info to help determine the source condition of timer errors. (bugreport:1860)
* Fixed crash in skill_castend_id. (bugreport:1860) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12968 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog-Trunk.txt5
-rw-r--r--src/common/timer.c21
-rw-r--r--src/map/skill.c21
3 files changed, 36 insertions, 11 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 201427743..bf2623489 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -3,7 +3,10 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
-2008/07/16
+2008/07/20
+ * Simplified the search in pop_timer_heap and added more debug info to help
+ determine the source condition of timer errors. (bugreport:1860)
+ * Fixed crash in skill_castend_id. (bugreport:1860) [FlavioJS]
* Corrected #storagelist target typo (bugreport:1873) [SketchyPhoenix]
2008/07/16
diff --git a/src/common/timer.c b/src/common/timer.c
index 882ddd705..84380c9f9 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -4,6 +4,7 @@
#include "../common/cbasetypes.h"
#include "../common/malloc.h"
#include "../common/showmsg.h"
+#include "../common/db.h"
#include "timer.h"
#include <stdio.h>
@@ -145,6 +146,7 @@ unsigned int gettick(void)
* CORE : Timer Heap
*--------------------------------------*/
+// root at index 0
#define BHEAP_PARENT(pos) ( ((pos) - 1)/2 )
#define BHEAP_LEFT(pos) ( (pos)*2 + 1 )
#define BHEAP_RIGHT(pos) ( (pos)*2 + 2 )
@@ -166,7 +168,7 @@ void push_timer_heap(int tid)
memset(timer_heap + (timer_heap_max - 256), 0, sizeof(int)*256);
}
- // add the timer
+ // add the timer at the end
pos = timer_heap_num++;
timer_heap[pos] = tid;
// restore binary heap properties
@@ -187,6 +189,10 @@ bool pop_timer_heap(int tid)
int pos;
// find the timer
+#if 1
+ // trying a simple array search
+ ARR_FIND(0, timer_heap_num, pos, timer_heap[pos] == tid);
+#else
pos = 0;
while( pos < timer_heap_num )
{// search in the order current-left-right
@@ -220,10 +226,11 @@ bool pop_timer_heap(int tid)
}
pos = right;
}
+#endif
if( pos >= timer_heap_num )
return false;// not found
- // remove timer
+ // remove timer (replace with last one)
timer_heap[pos] = timer_heap[--timer_heap_num];
// restore binary heap properties
while( pos < timer_heap_num )
@@ -231,9 +238,9 @@ bool pop_timer_heap(int tid)
int left = BHEAP_LEFT(pos);
int right = BHEAP_RIGHT(pos);
if( left < timer_heap_num && DIFF_TICK(timer_data[timer_heap[pos]].tick, timer_data[timer_heap[left]].tick) > 0 )
- {
+ {// left exists and has smaller tick
if( right < timer_heap_num && DIFF_TICK(timer_data[timer_heap[left]].tick, timer_data[timer_heap[right]].tick) > 0 )
- {
+ {// right exists and has even smaller tick
swap(timer_heap[pos], timer_heap[right]);
pos = right;
}
@@ -244,7 +251,7 @@ bool pop_timer_heap(int tid)
}
}
else if( right < timer_heap_num && DIFF_TICK(timer_data[timer_heap[pos]].tick, timer_data[timer_heap[right]].tick) > 0 )
- {
+ {// right exists and has smaller tick
swap(timer_heap[pos], timer_heap[right]);
pos = right;
}
@@ -429,6 +436,8 @@ int delete_timer(int tid, TimerFunc func)
timer_data[tid].type = TIMER_FORCE_REMOVE|TIMER_REMOVE_HEAP;
else if( pop_timer_heap(tid) )
release_timer(tid);
+ else if( (timer_data[tid].type|TIMER_REMOVE_HEAP) == 0 )
+ ShowDebug("delete_timer: failed to remove timer %d (%08x(%s), type=%d)\n", tid, (int)func, search_timer_func_list(func), timer_data[tid].type);
return 0;
}
@@ -474,7 +483,7 @@ int do_timer(unsigned int tick)
// process all timers one by one
while( timer_heap_num )
{
- int tid = timer_heap[0]; // first element in heap (=>smallest)
+ int tid = timer_heap[0]; // first element in heap (smallest tick)
diff = DIFF_TICK(timer_data[tid].tick, tick);
if( diff > 0 )
diff --git a/src/map/skill.c b/src/map/skill.c
index cf81ad720..d817e5eba 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -5216,15 +5216,28 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
*------------------------------------------*/
int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
{
- struct block_list *target, *src = map_id2bl(id);
+ struct block_list* target = NULL;
+ struct block_list* src = NULL;
struct map_session_data* sd = NULL;
struct homun_data* hd = NULL; //[orn]
struct mob_data* md = NULL;
- struct unit_data* ud = unit_bl2ud(src);
- struct status_change *sc = NULL;
+ struct unit_data* ud = NULL;
+ struct status_change* sc = NULL;
int inf,inf2,flag=0;
- nullpo_retr(0, ud);
+ src = map_id2bl(id);
+ if( src == NULL )
+ {
+ ShowDebug("skill_castend_id: src == NULL (tid=%d, id=%d)\n", tid, id);
+ return 0;// not found
+ }
+
+ ud = unit_bl2ud(src);
+ if( ud == NULL )
+ {
+ ShowDebug("skill_castend_id: ud == NULL (tid=%d, id=%d)\n", tid, id);
+ return 0;// ???
+ }
sd = BL_CAST(BL_PC, src);
hd = BL_CAST(BL_HOM, src);