Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Tracking segfaults

  1. #11

  2. #12
    Quote Originally Posted by Darkhog View Post
    I can send you sources, if you want to look into it.
    ok i can give it a shot

  3. #13
    Pm'ed Laggyluk, will PM imcold in a minute.

    //edit: PM'ed imcold as well.
    Last edited by Darkhog; 24-06-2013 at 04:08 PM. Reason: Because.

  4. #14
    Can you send it to me also. I would also like to try help you out.
    And besides since I'm closely folowing Factorio which also uses allegro game engine it would probably give me better idea of what it is posible to do with allegro and what not. This way I could probably give better suggestion to Factorio developers. And no Factorio is unfortunately not made with pascal.

  5. #15
    You're getting errors due to changing the Chunk.Data in your keyboard handling code. The your keyboard handler is running in another context/thread (read the doc carefully: http://allegro-pas.sourceforge.net/d...install_int_ex). What does this mean? The data modified in the handler can change at any moment, independently of your main loop routine - if it changes when you're in your Draw routine, all hell's gonna break loose due to invalid pointers etc.
    The solution is to just set a flag to signal that a world refresh is needed, and check it in the main loop (and there should be a lock around the flag, to do things 100% properly; but you can probably get away without it in this case).
    Code:
    var
        update_chunks: boolean;
    
      procedure RegenerateChunk;
      begin
        update_chunks := false;
        Chunk.Data:=WorldGenerator.GenerateChunkData(chunkx,0,18);
        Inc(chunkx);
        al_clear_to_color(perlin,al_makecol(255,0,255));
        for x:=0 to 100-1 do
        begin
          for y:=0 to 100-1 do
          begin
            al_putpixel(perlin,x,y,generate_pixel(x,y));
          end;
        end;
      end;
    
      procedure update_keyboard();
      begin
          Dec(lasted);
          dec(chunklasted);
          if (al_keyboard_needs_poll) then al_poll_keyboard;
          if ((al_key[AL_KEY_P]<>0) and (lasted<=0)) then begin pause:=not pause; lasted:=pausedelay; end;
          if not pause then begin
    
            if ((al_key[AL_KEY_SPACE]<>0) and (chunklasted<=0)) then
            begin
              update_chunks := true;
              chunklasted:=pausedelay;
            end;
          end;
      end;
    main routine:
    Code:
          repeat
            draw;
            if update_chunks then
                RegenerateChunk;
          until (al_key[AL_KEY_Q]<>0) or quit;
    Last edited by imcold; 24-06-2013 at 07:40 PM.

  6. #16
    imcold that fixed it, I think. Thank you!

  7. #17
    Hi. I know I'm late but ...
    Quote Originally Posted by Darkhog View Post
    imcold that fixed it, I think. Thank you!
    Does it means that the code you send me by PM was fixed?

    Anyway, the way you made the main loop and the keyboard handler aren't recommendable. You shouldn't manage the user input in an interruption (as documentation says it's called in "interruption time" not in "execution time"). I recommend you to read the timers tutorial and the sources of the Allegro.pas' demo game.
    No signature provided yet.

  8. #18
    Well, when I've tried it in mainloop it ran too fast. Plus I only need keyboard to be read 60 frames per second, all over this would be excessive.

  9. #19
    Well, you can set the speed or your "logic loop", even use two counters. I don't see the problem.
    No signature provided yet.

  10. #20
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    The rate of any spinning threads and/or polling you need to do should all be configurable. As a general rule of thumb you should avoid maxing a bunch of threads out as it leads to more unpredictable switches between threads by the OS Scheduler (IE what if you don't return to the audio thread quickly enough to keep the output buffer filled etc) You want things as fast as they'll go whilst retaining a consistent execution rate.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •