delphi 10 seattle "Automatic Reference Counting"问题

测试Embarcadero® Delphi 10 Seattle Version 23.0.20618.2753,Multi-Device Application。

从资源中读取图片:

procedure TKsColorBall.GetImagesFromResource;
var
  i:integer;
  Bmp:TBitmap;   
  s:string;
  RS:TResourceStream;
begin
  for i:=IconList.Count-1 downto 0 do
    TObject(IconList.Items[i]).Free;
  IconList.Clear;

  for i:=1 to FOption.IconKind do
  begin
    Bmp:=TBitmap.Create;
    s:=Char(Ord('A')+i-1)+FOption.IconSystem;
    RS := TResourceStream.Create(hInstance, s, RT_RCDATA);
    Bmp.LoadFromStream(RS);
    RS.Free;
    IconList.Add(Bmp);
    Bmp:=nil;
  end;
end;
然后,其它地方从IconList列表中取出来绘图:

procedure TKsColorBall.New3Ball;
var
  Blanks:TStringList;

  procedure PickOutBlank;
  var
    i,j:integer;
  begin
    Blanks.Clear;
    for i:=1 to GapCount do
    for j:=1 to GapCount do if BallList[i,j].Color=-1 then
    begin
      Blanks.Add(InttoStr(i)+','+InttoStr(j));
    end;
  end;
var
  Bmp:TBitmap;
  Row,Col,BallIndex,ColorIndex:integer;
  i,j,n:integer;
begin
  Blanks:=TStringList.Create;
  try
    PickOutBlank;
    if Blanks.Count=0 then
    begin
      if Assigned(FOnGameOver) then FOnGameOver(self);
      exit;
    end;

    n:=Blanks.Count;
    if n>FOption.NewBallCount then n:=FOption.NewBallCount;
    Randomize;
    for i:=1 to n do
    begin
      BallIndex:=Random(Blanks.Count);   //get a new ball from blanks
      j:=Pos(',',Blanks[BallIndex]);
      Row:=StrToInt(Copy(Blanks[BallIndex],1,j-1));
      Col:=StrToInt(Copy(Blanks[BallIndex],j+1,Length(Blanks[BallIndex])-j));
      Blanks.Delete(BallIndex);

      ColorIndex:=New3BallColor[i];
      if ColorIndex=-1 then ColorIndex:=1+Random(FOption.IconKind);   //ball color
      Bmp:=IconList[ColorIndex-1];
      WorkCanvas.BeginScene();
      try
        WorkCanvas.DrawBitmap(Bmp,RectF(0,0,Bmp.Width,Bmp.Height),
          RectF(Col*Gap+4,Row*Gap+4,Col*Gap+4+Bmp.Width,Row*Gap+4+Bmp.Height),
          100,false);
      finally
        WorkCanvas.EndScene;
      end;
      Bmp:=nil;
      BallList[Row,Col].Color:=ColorIndex;

      KillBall(Row,Col);
      PickOutBlank;   //pickout blank again
      if Blanks.Count=0 then
      begin
        CopyWorkCanvas;
        if Assigned(FOnGameOver) then FOnGameOver(self);
        exit;
      end;
    end;
  finally
    Blanks.Free;
  end;

  NewYuGao;

  DrawYuGao;
end;

在Windows下运行ok,但是在android下,总是在取出Bmp来用的部分这行崩溃:

Bmp:=IconList[ColorIndex-1];
错误为:Project flows.apk raised exception class Segmentation fault (11).

google查找,应该是"Automatic Reference Counting"引起的问题,在bmp变量前尝试加上[weak]或[Unsafe]都不行。

http://blog.marcocantu.com/blog/automatic_reference_counting_for_delphi.html

后来发现,IconList是classes.TList类型,在AUTOREFCOUNT下是禁止使用的,于是换成System.Generics.Defaults.TList<TBitmap>或System.Generics.Collections.TObjectList<TBitmap>,在android下测试ok。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

火星牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值