Illegal Exception

Started by Joe, Tue 12/09/2006 16:10:12

Previous topic - Next topic

Joe

---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x00463081 ; program pointer is +6, ACI version 2.72.920, gtags (6,1)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and notify CJ on the Tech forum.

in Global script (line 20)
from Room 5 script (line 15)

---------------------------

This is Global Script line 20:
Code: ags

function SayBackgroundAnimating(Character *Char, const string message,...){  
Char.LockView(Char.SpeechView);
int timer= 300;
Overlay *over=Overlay.CreateTextual(Char.x,Char.y-100,100,1,Char.SpeechColor,message);
Char.Animate(0, 4, eRepeat,eNoBlock,eForwards);
while(timer>0){
timer--;
}
Char.Animate(0, 4, eOnce,eNoBlock,eForwards);
over.Remove();
Char.UnlockView();
}


This is room five line 15:
Code: ags

SayBackgroundAnimating(cCupon, "  Buy today!!!!   ");
Copinstar © Oficial Site

Khris

Does the first line really contain "..." at the end?

Two other things: The while loop won't pause the game more than a fraction of a millisecond. Even setting timer to 150.000 before (AGS's while loop limit) won't create a significant pause.
And I'm not sure what AGS does if you unlock a character's view while it's animating. Could be harmless, though.

Did you call this function in room five's rep_ex() by any chance?

Joe

Quote from: KhrisMUC on Tue 12/09/2006 16:28:54
Does the first line really contain "..." at the end?
No it does not
Quote from: KhrisMUC on Tue 12/09/2006 16:28:54
Did you call this function in room five's rep_ex() by any chance?
Yes I did
Copinstar © Oficial Site

Pumaman

Whilst this shouldn't cause a crash, it won't do anything either:

while(timer>0){
timer--;
}

Also, which of the lines of code is actually line 20?

Joe

This one:

function SayBackgroundAnimating(Character *Char, const string message){
Copinstar © Oficial Site

Khris

Quote from: Joe Carl on Tue 12/09/2006 16:49:18
Quote from: KhrisMUC on Tue 12/09/2006 16:28:54
Did you call this function in room five's rep_ex() by any chance?
Yes I did

That's not so good, because that means the function is going to get called 40 times a second.

Another thing is that everything inside the function happens way too fast for the player to even see. The overlay is removed immidiately after it was created, and the two Animate commands are obsolete because UnlockView is called directly afterwards.

I'd first think of a working concept to achieve what you want, the error will probably resolve itself in the process.

Joe

#6
Quote from: KhrisMUC link=topic=28318.msg359950#msg359950
Quote
That's not so good, because that means the function is going to get called 40 times a second.
Thats not gonna happen because when player entres in room a timer is set to 400
then, in the rep_ex room funtion theres a if (IsTimerExpired(1)==1){//Do my function and set the timer to 400 again}
Copinstar © Oficial Site

monkey0506

#7
But still the player wouldn't animate nor would the overlay be displayed (at least not for a reasonable amount of time in any case).

Perhaps you should do something like this:

Code: ags
Overlay* SpeechOverlays[20]; // 20 overlays is current max
Character* SpeechChars[20]; // to store the animating char for each overlay
int SpeechTimer[20]; // timers for each overlay
int SpeechCount = 0; // to keep count of the overlays set to prevent overflow

function SayBackgroundAnimating(Character* Char, const string message) { // unless you use any old-style strings in your scripts, "String" would work in place of "const string" here
  if (SpeechCount == 20) return; // you can only have 20 overlays at once...
  int i = 0;
  int index = -1;
  while (i < 20) {
    if (SpeechOverlays[index] == null) {
      // find an empty item to use!
      index = i;
      i = 20;
      }
    i++;
    }
  if (index == -1) return; // this would only happen if you go mucking around with removing the overlays yourself without setting them to null instead of using the following "RemoveBackgroundSpeech" function (which is run automatically) ;)
  SpeechOverlays[index] = Overlay.CreateTextual(Char.x, Char.y - 100, 100, 1, message);
  if ((Char != null) && (Char.SpeechView)) { // check to make sure Char is a valid pointer, and that the Char has a speech view set
    Char.LockView(Char.SpeechView);
    Char.Animate(Char.Loop, Char.AnimationSpeed, eRepeat, eNoBlock, eForwards); // I changed this to use the character's current loop and animation speed
    SpeechChars[index] = Char;
    }
  SpeechTimer[index] = 300;
  SpeechCount++;
  }

function RemoveBackgroundSpeech(int index) {
  // this is called automatically when each item's timer runs out
  // you can also call it to remove the speech prematurely
  if ((index < 0) || (index >= 20)) return;
  if ((SpeechOverlays[index] == null) && (SpeechChars[index] == null) && (!SpeechTimer[index])) return; // item is already empty / has already been removed
  if (SpeechOverlays[index] != null) SpeechOverlays[index].Remove();
  if (SpeechChars[index] != null) SpeechChars.UnlockView();
  SpeechOverlays[index] = null;
  SpeechChars[index] = null;
  SpeechTimer[index] = 0;
  SpeechCount--;
  }

// rep_ex
int i = 0;
while (i < 20) {
  if (SpeechOverlays[i] != null) {
    if (SpeechTimer[i]) SpeechTimer[i]--;
    else RemoveBackgroundSpeech(i);
    }
  i++;
  }


It's a bit more complicated than your original idea, but it should be error free and will allow you to properly animate up to 20 characters while they speak in the background (I actually didn't test this code).

Also with this code you don't need to use AGS's built-in timers.

[EDIT:]

I've made a few modifications to the code. One of which prevents RemoveBackgroundSpeech running if the item is already empty or it's already been removed...which would make SpeechCount invalid and screw up everything...but it's fixed now ;)

Joe

Thanks for your nice reply :)
I'll try it as soon as i can.
Copinstar © Oficial Site

SMF spam blocked by CleanTalk